"""FFmpeg autoconf checks mirroring the configure script."""

load("@rules_cc_autoconf//autoconf:checks.bzl", "checks")

def _check_mathfunc(func, nargs = 1):
    """Mirrors FFmpeg's check_mathfunc (configure line 1372).

    Generates an AC_CHECK_LIB probe that includes <math.h> and calls the
    function with properly-typed float arguments. The default AC_CHECK_LIB
    template declares `char func()` which conflicts with the real prototype
    on ARM64 (char vs double return type), so custom code is required.

    If the check fails, config.h.in's #ifndef fallback defaults the HAVE_*
    macro to 1 (these are standard C99/POSIX functions available on all
    supported platforms).

    Args:
        func: Name of the math function to check (e.g. "cbrt").
        nargs: Number of arguments the function takes (1 or 2).

    Returns:
        A JSON-encoded check suitable for FFMPEG_CONFIG_CHECKS.
    """
    if nargs == 2:
        code = "#include <math.h>\nfloat foo(float f, float g) { return %s(f, g); }\nint main(void){ return (int) foo; }" % func
    else:
        code = "#include <math.h>\nfloat foo(float f) { return %s(f); }\nint main(void){ return (int) foo; }" % func
    return checks.AC_CHECK_LIB("m", func, define = "HAVE_" + func.upper(), code = code)

FFMPEG_CONFIG_CHECKS = [
    # ========== Architecture detection (ARCH_LIST) ==========
    checks.AC_TRY_COMPILE(name = "ac_cv_arch_aarch64", define = "ARCH_AARCH64", code = "#if !(defined(__aarch64__))\n#error\n#endif"),
    checks.AC_TRY_COMPILE(define = "ARCH_ARM", code = "#if !(defined(__arm__))\n#error\n#endif"),
    checks.AC_TRY_COMPILE(define = "ARCH_IA64", code = "#if !(defined(__ia64__))\n#error\n#endif"),
    checks.AC_TRY_COMPILE(define = "ARCH_LOONGARCH", code = "#if !(defined(__loongarch__))\n#error\n#endif"),
    checks.AC_TRY_COMPILE(define = "ARCH_LOONGARCH32", code = "#if !(defined(__loongarch32__))\n#error\n#endif"),
    checks.AC_TRY_COMPILE(define = "ARCH_LOONGARCH64", code = "#if !(defined(__loongarch64__))\n#error\n#endif"),
    checks.AC_TRY_COMPILE(define = "ARCH_M68K", code = "#if !(defined(__m68k__))\n#error\n#endif"),
    checks.AC_TRY_COMPILE(define = "ARCH_MIPS", code = "#if !(defined(__mips__))\n#error\n#endif"),
    checks.AC_TRY_COMPILE(define = "ARCH_MIPS64", code = "#if !(defined(__mips64))\n#error\n#endif"),
    checks.AC_TRY_COMPILE(define = "ARCH_PARISC", code = "#if !(defined(__hppa__))\n#error\n#endif"),
    checks.AC_TRY_COMPILE(define = "ARCH_PPC", code = "#if !(defined(__powerpc__))\n#error\n#endif"),
    checks.AC_TRY_COMPILE(define = "ARCH_PPC64", code = "#if !(defined(__powerpc64__))\n#error\n#endif"),
    checks.AC_TRY_COMPILE(define = "ARCH_RISCV", code = "#if !(defined(__riscv))\n#error\n#endif"),
    checks.AC_TRY_COMPILE(define = "ARCH_S390", code = "#if !(defined(__s390__))\n#error\n#endif"),
    checks.AC_TRY_COMPILE(define = "ARCH_SPARC", code = "#if !(defined(__sparc__))\n#error\n#endif"),
    checks.AC_TRY_COMPILE(define = "ARCH_SPARC64", code = "#if !(defined(__sparc64__))\n#error\n#endif"),
    checks.AC_TRY_COMPILE(define = "ARCH_TILEGX", code = "#if !(defined(__tilegx__))\n#error\n#endif"),
    checks.AC_TRY_COMPILE(define = "ARCH_TILEPRO", code = "#if !(defined(__tilepro__))\n#error\n#endif"),
    checks.AC_TRY_COMPILE(define = "ARCH_X86", code = "#if !(defined(__i386__) || defined(__x86_64__))\n#error\n#endif"),
    checks.AC_TRY_COMPILE(define = "ARCH_X86_32", code = "#if !(defined(__i386__))\n#error\n#endif"),
    checks.AC_TRY_COMPILE(define = "ARCH_X86_64", code = "#if !(defined(__x86_64__))\n#error\n#endif"),

    # ========== OS metadata ==========
    checks.AC_TRY_COMPILE(name = "ac_cv_os_darwin", code = "#if !defined(__APPLE__)\n#error\n#endif"),
    checks.AC_SUBST("OS_NAME", condition = "ac_cv_os_darwin", if_true = "darwin", if_false = "linux"),
    checks.AC_SUBST("SLIBSUF", condition = "ac_cv_os_darwin", if_true = ".dylib", if_false = ".so"),
    checks.AC_SUBST("EXTERN_PREFIX", condition = "ac_cv_os_darwin", if_true = "_", if_false = ""),
    checks.AC_SUBST("EXTERN_ASM", condition = "ac_cv_os_darwin", if_true = "_", if_false = ""),

    # ========== Conditional metadata ==========
    checks.AC_DEFINE("AS_ARCH_LEVEL", condition = "ac_cv_arch_aarch64", if_true = "armv8.6-a+crc", if_false = None),

    # ========== Header checks (HEADERS_LIST) ==========
    checks.AC_CHECK_HEADER("arpa/inet.h", define = "HAVE_ARPA_INET_H"),
    checks.AC_CHECK_HEADER("asm/hwprobe.h", define = "HAVE_ASM_HWPROBE_H"),
    checks.AC_CHECK_HEADER("asm/types.h", define = "HAVE_ASM_TYPES_H"),
    checks.AC_CHECK_HEADER("cdio/paranoia.h", define = "HAVE_CDIO_PARANOIA_H"),
    checks.AC_CHECK_HEADER("cdio/paranoia/paranoia.h", define = "HAVE_CDIO_PARANOIA_PARANOIA_H"),
    checks.AC_CHECK_HEADER("cuda.h", define = "HAVE_CUDA_H"),
    checks.AC_CHECK_HEADER("dispatch/dispatch.h", define = "HAVE_DISPATCH_DISPATCH_H"),
    checks.AC_CHECK_HEADER("dev/bktr/ioctl_bt848.h", define = "HAVE_DEV_BKTR_IOCTL_BT848_H"),
    checks.AC_CHECK_HEADER("dev/bktr/ioctl_meteor.h", define = "HAVE_DEV_BKTR_IOCTL_METEOR_H"),
    checks.AC_CHECK_HEADER("dev/ic/bt8xx.h", define = "HAVE_DEV_IC_BT8XX_H"),
    checks.AC_CHECK_HEADER("dev/video/bktr/ioctl_bt848.h", define = "HAVE_DEV_VIDEO_BKTR_IOCTL_BT848_H"),
    checks.AC_CHECK_HEADER("dev/video/meteor/ioctl_meteor.h", define = "HAVE_DEV_VIDEO_METEOR_IOCTL_METEOR_H"),
    checks.AC_CHECK_HEADER("direct.h", define = "HAVE_DIRECT_H"),
    checks.AC_CHECK_HEADER("dirent.h", define = "HAVE_DIRENT_H"),
    checks.AC_CHECK_HEADER("dxgidebug.h", define = "HAVE_DXGIDEBUG_H"),
    checks.AC_CHECK_HEADER("dxva.h", define = "HAVE_DXVA_H"),
    checks.AC_CHECK_HEADER("ES2/gl.h", define = "HAVE_ES2_GL_H"),
    checks.AC_CHECK_HEADER("gsm.h", define = "HAVE_GSM_H"),
    checks.AC_CHECK_HEADER("io.h", define = "HAVE_IO_H"),
    checks.AC_CHECK_HEADER("linux/dma-buf.h", define = "HAVE_LINUX_DMA_BUF_H"),
    checks.AC_CHECK_HEADER("linux/perf_event.h", define = "HAVE_LINUX_PERF_EVENT_H"),
    checks.AC_CHECK_HEADER("machine/ioctl_bt848.h", define = "HAVE_MACHINE_IOCTL_BT848_H"),
    checks.AC_CHECK_HEADER("machine/ioctl_meteor.h", define = "HAVE_MACHINE_IOCTL_METEOR_H"),
    checks.AC_CHECK_HEADER("malloc.h", define = "HAVE_MALLOC_H"),
    checks.AC_CHECK_HEADER("opencv2/core/core_c.h", define = "HAVE_OPENCV2_CORE_CORE_C_H"),
    checks.AC_CHECK_HEADER("OpenGL/gl3.h", define = "HAVE_OPENGL_GL3_H"),
    checks.AC_CHECK_HEADER("poll.h", define = "HAVE_POLL_H"),
    checks.AC_CHECK_HEADER("pthread_np.h", define = "HAVE_PTHREAD_NP_H"),
    checks.AC_CHECK_HEADER("sys/hwprobe.h", define = "HAVE_SYS_HWPROBE_H"),
    checks.AC_CHECK_HEADER("sys/param.h", define = "HAVE_SYS_PARAM_H"),
    checks.AC_CHECK_HEADER("sys/resource.h", define = "HAVE_SYS_RESOURCE_H"),
    checks.AC_CHECK_HEADER("sys/select.h", define = "HAVE_SYS_SELECT_H"),
    checks.AC_CHECK_HEADER("sys/soundcard.h", define = "HAVE_SYS_SOUNDCARD_H"),
    checks.AC_CHECK_HEADER("sys/time.h", define = "HAVE_SYS_TIME_H"),
    checks.AC_CHECK_HEADER("sys/un.h", define = "HAVE_SYS_UN_H"),
    checks.AC_CHECK_HEADER("sys/videoio.h", define = "HAVE_SYS_VIDEOIO_H"),
    checks.AC_CHECK_HEADER("termios.h", define = "HAVE_TERMIOS_H"),
    checks.AC_CHECK_HEADER("net/udplite.h", define = "HAVE_UDPLITE_H"),
    checks.AC_CHECK_HEADER("unistd.h", define = "HAVE_UNISTD_H"),
    checks.AC_CHECK_HEADER("valgrind/valgrind.h", define = "HAVE_VALGRIND_VALGRIND_H"),
    checks.AC_CHECK_HEADER("windows.h", define = "HAVE_WINDOWS_H"),
    checks.AC_CHECK_HEADER("winsock2.h", define = "HAVE_WINSOCK2_H"),

    # ========== System function checks (SYSTEM_FUNCS) ==========
    checks.AC_CHECK_FUNC("access", define = "HAVE_ACCESS"),
    checks.AC_TRY_LINK(define = "HAVE_ALIGNED_MALLOC", code = "long x = (long)_aligned_malloc; (void)x;", includes = ["#include <malloc.h>"]),
    checks.AC_TRY_LINK(define = "HAVE_ARC4RANDOM_BUF", code = "long x = (long)arc4random_buf; (void)x;", includes = ["#include <stdlib.h>"]),
    checks.AC_TRY_LINK(define = "HAVE_CLOCK_GETTIME", code = "long x = (long)clock_gettime; (void)x;", includes = ["#include <time.h>"]),
    checks.AC_TRY_LINK(define = "HAVE_CLOSESOCKET", code = "long x = (long)closesocket; (void)x;", includes = ["#include <winsock2.h>"]),
    checks.AC_TRY_LINK(define = "HAVE_COMMANDLINETOARGVW", code = "long x = (long)CommandLineToArgvW; (void)x;", includes = ["#include <windows.h>", "#include <shellapi.h>"]),
    checks.AC_TRY_LINK(define = "HAVE_ELF_AUX_INFO", code = "long x = (long)elf_aux_info; (void)x;", includes = ["#include <sys/auxv.h>"]),
    checks.AC_CHECK_FUNC("fcntl", define = "HAVE_FCNTL"),
    checks.AC_CHECK_FUNC("getaddrinfo", define = "HAVE_GETADDRINFO"),
    checks.AC_TRY_LINK(define = "HAVE_GETAUXVAL", code = "long x = (long)getauxval; (void)x;", includes = ["#include <sys/auxv.h>"]),
    checks.AC_TRY_LINK(define = "HAVE_GETENV", code = "long x = (long)getenv; (void)x;", includes = ["#include <stdlib.h>"]),
    checks.AC_CHECK_FUNC("gethrtime", define = "HAVE_GETHRTIME"),
    checks.AC_CHECK_FUNC("getopt", define = "HAVE_GETOPT"),
    checks.AC_TRY_LINK(define = "HAVE_GETMODULEHANDLE", code = "long x = (long)GetModuleHandle; (void)x;", includes = ["#include <windows.h>"]),
    checks.AC_TRY_LINK(define = "HAVE_GETPROCESSAFFINITYMASK", code = "long x = (long)GetProcessAffinityMask; (void)x;", includes = ["#include <windows.h>"]),
    checks.AC_TRY_LINK(define = "HAVE_GETPROCESSMEMORYINFO", code = "long x = (long)GetProcessMemoryInfo; (void)x;", includes = ["#include <windows.h>", "#include <psapi.h>"]),
    checks.AC_TRY_LINK(define = "HAVE_GETPROCESSTIMES", code = "long x = (long)GetProcessTimes; (void)x;", includes = ["#include <windows.h>"]),
    checks.AC_CHECK_FUNC("getrusage", define = "HAVE_GETRUSAGE"),
    checks.AC_TRY_LINK(define = "HAVE_GETSTDHANDLE", code = "long x = (long)GetStdHandle; (void)x;", includes = ["#include <windows.h>"]),
    checks.AC_TRY_LINK(define = "HAVE_GETSYSTEMTIMEASFILETIME", code = "long x = (long)GetSystemTimeAsFileTime; (void)x;", includes = ["#include <windows.h>"]),
    checks.AC_CHECK_FUNC("gettimeofday", define = "HAVE_GETTIMEOFDAY"),
    checks.AC_TRY_LINK(define = "HAVE_GLOB", code = "long x = (long)glob; (void)x;", includes = ["#include <glob.h>"]),
    checks.AC_TRY_LINK(define = "HAVE_GLXGETPROCADDRESS", code = "long x = (long)glXGetProcAddress; (void)x;", includes = ["#include <GL/glx.h>"]),
    checks.AC_TRY_LINK(define = "HAVE_GMTIME_R", code = "long x = (long)gmtime_r; (void)x;", includes = ["#include <time.h>"]),
    checks.AC_CHECK_FUNC("inet_aton", define = "HAVE_INET_ATON"),
    checks.AC_CHECK_FUNC("isatty", define = "HAVE_ISATTY"),
    checks.AC_TRY_LINK(define = "HAVE_KBHIT", code = "long x = (long)kbhit; (void)x;", includes = ["#include <conio.h>"]),
    checks.AC_TRY_LINK(define = "HAVE_LOCALTIME_R", code = "long x = (long)localtime_r; (void)x;", includes = ["#include <time.h>"]),
    checks.AC_TRY_LINK(define = "HAVE_LSTAT", code = "long x = (long)lstat; (void)x;", includes = ["#include <sys/stat.h>"]),
    checks.AC_TRY_LINK(define = "HAVE_LZO1X_999_COMPRESS", code = "long x = (long)lzo1x_999_compress; (void)x;", includes = ["#include <lzo/lzo1x.h>"]),
    checks.AC_TRY_LINK(define = "HAVE_MACH_ABSOLUTE_TIME", code = "long x = (long)mach_absolute_time; (void)x;", includes = ["#include <mach/mach_time.h>"]),
    checks.AC_TRY_LINK(define = "HAVE_MAPVIEWOFFILE", code = "long x = (long)MapViewOfFile; (void)x;", includes = ["#include <windows.h>"]),
    checks.AC_CHECK_FUNC("memalign", define = "HAVE_MEMALIGN"),
    checks.AC_CHECK_FUNC("mkstemp", define = "HAVE_MKSTEMP"),
    checks.AC_CHECK_FUNC("mmap", define = "HAVE_MMAP"),
    checks.AC_CHECK_FUNC("mprotect", define = "HAVE_MPROTECT"),
    checks.AC_TRY_LINK(define = "HAVE_NANOSLEEP", code = "long x = (long)nanosleep; (void)x;", includes = ["#include <time.h>"]),
    checks.AC_TRY_LINK(define = "HAVE_PEEKNAMEDPIPE", code = "long x = (long)PeekNamedPipe; (void)x;", includes = ["#include <windows.h>"]),
    checks.AC_CHECK_FUNC("posix_memalign", define = "HAVE_POSIX_MEMALIGN"),
    checks.AC_TRY_LINK(define = "HAVE_PRCTL", code = "long x = (long)prctl; (void)x;", includes = ["#include <sys/prctl.h>"]),
    checks.AC_CHECK_LIB("pthread", "pthread_cancel", define = "HAVE_PTHREAD_CANCEL"),
    checks.AC_CHECK_LIB("pthread", "pthread_set_name_np", define = "HAVE_PTHREAD_SET_NAME_NP"),
    checks.AC_CHECK_LIB("pthread", "pthread_setname_np", define = "HAVE_PTHREAD_SETNAME_NP"),
    checks.AC_CHECK_FUNC("sched_getaffinity", define = "HAVE_SCHED_GETAFFINITY"),
    checks.AC_CHECK_FUNC("SecItemImport", define = "HAVE_SECITEMIMPORT"),
    checks.AC_TRY_LINK(define = "HAVE_SETCONSOLETEXTATTRIBUTE", code = "long x = (long)SetConsoleTextAttribute; (void)x;", includes = ["#include <windows.h>"]),
    checks.AC_TRY_LINK(define = "HAVE_SETCONSOLECTRLHANDLER", code = "long x = (long)SetConsoleCtrlHandler; (void)x;", includes = ["#include <windows.h>"]),
    checks.AC_TRY_LINK(define = "HAVE_SETDLLDIRECTORY", code = "long x = (long)SetDllDirectory; (void)x;", includes = ["#include <windows.h>"]),
    checks.AC_TRY_LINK(define = "HAVE_SETMODE", code = "long x = (long)setmode; (void)x;", includes = ["#include <io.h>"]),
    checks.AC_CHECK_FUNC("setrlimit", define = "HAVE_SETRLIMIT"),
    checks.AC_TRY_LINK(define = "HAVE_SLEEP", code = "long x = (long)Sleep; (void)x;", includes = ["#include <windows.h>"]),
    checks.AC_CHECK_FUNC("strerror_r", define = "HAVE_STRERROR_R"),
    checks.AC_CHECK_FUNC("sysconf", define = "HAVE_SYSCONF"),
    checks.AC_CHECK_FUNC("sysctl", define = "HAVE_SYSCTL"),
    checks.AC_TRY_LINK(define = "HAVE_SYSCTLBYNAME", code = "long x = (long)sysctlbyname; (void)x;", includes = ["#include <sys/sysctl.h>"]),
    checks.AC_CHECK_FUNC("tempnam", define = "HAVE_TEMPNAM"),
    checks.AC_CHECK_FUNC("usleep", define = "HAVE_USLEEP"),
    checks.AC_TRY_LINK(define = "HAVE_UTGETOSTYPEFROMSTRING", code = "long x = (long)UTGetOSTypeFromString; (void)x;", includes = ["#include <CoreServices/CoreServices.h>"]),
    checks.AC_TRY_LINK(define = "HAVE_VIRTUALALLOC", code = "long x = (long)VirtualAlloc; (void)x;", includes = ["#include <windows.h>"]),
    checks.AC_TRY_LINK(define = "HAVE_WGLGETPROCADDRESS", code = "long x = (long)wglGetProcAddress; (void)x;", includes = ["#include <windows.h>"]),

    # ========== Math function checks (MATH_FUNCS) ==========
    # Mirrors FFmpeg's check_mathfunc loop (configure line 6849).
    _check_mathfunc("atan2f", nargs = 2),
    _check_mathfunc("atanf"),
    _check_mathfunc("cbrt"),
    _check_mathfunc("cbrtf"),
    _check_mathfunc("copysign", nargs = 2),
    _check_mathfunc("cosf"),
    _check_mathfunc("erf"),
    _check_mathfunc("exp2"),
    _check_mathfunc("exp2f"),
    _check_mathfunc("expf"),
    _check_mathfunc("hypot", nargs = 2),
    # isfinite/isinf/isnan are C99 macros, not linkable symbols.
    checks.AC_TRY_LINK(define = "HAVE_ISFINITE", code = "volatile float x = 1.0f; return (int)isfinite(x);", includes = ["#include <math.h>"]),
    checks.AC_TRY_LINK(define = "HAVE_ISINF", code = "volatile float x = 1.0f; return (int)isinf(x);", includes = ["#include <math.h>"]),
    checks.AC_TRY_LINK(define = "HAVE_ISNAN", code = "volatile float x = 1.0f; return (int)isnan(x);", includes = ["#include <math.h>"]),
    _check_mathfunc("ldexpf", nargs = 2),
    _check_mathfunc("llrint"),
    _check_mathfunc("llrintf"),
    _check_mathfunc("log2"),
    _check_mathfunc("log2f"),
    _check_mathfunc("log10f"),
    _check_mathfunc("lrint"),
    _check_mathfunc("lrintf"),
    _check_mathfunc("powf", nargs = 2),
    _check_mathfunc("rint"),
    _check_mathfunc("round"),
    _check_mathfunc("roundf"),
    _check_mathfunc("sinf"),
    _check_mathfunc("trunc"),
    _check_mathfunc("truncf"),

    # ========== Type and struct checks (TYPES_LIST) ==========
    checks.AC_TRY_COMPILE(define = "HAVE_DPI_AWARENESS_CONTEXT", code = "DPI_AWARENESS_CONTEXT x; (void)x;", includes = ["#include <windows.h>"]),
    checks.AC_TRY_COMPILE(define = "HAVE_IDXGIOUTPUT5", code = "IDXGIOutput5 *x; (void)x;", includes = ["#include <windows.h>", "#include <dxgi1_5.h>"]),
    checks.AC_TRY_COMPILE(define = "HAVE_SOCKLEN_T", code = "socklen_t x = 0; (void)x;", includes = ["#include <sys/types.h>", "#include <sys/socket.h>"]),
    checks.AC_TRY_COMPILE(define = "HAVE_STRUCT_ADDRINFO", code = "struct addrinfo x; (void)x;", includes = ["#include <netdb.h>"]),
    checks.AC_TRY_COMPILE(define = "HAVE_STRUCT_GROUP_SOURCE_REQ", code = "struct group_source_req x; (void)x;", includes = ["#include <netinet/in.h>"]),
    checks.AC_TRY_COMPILE(define = "HAVE_STRUCT_IP_MREQ_SOURCE", code = "struct ip_mreq_source x; (void)x;", includes = ["#include <netinet/in.h>"]),
    checks.AC_TRY_COMPILE(define = "HAVE_STRUCT_IPV6_MREQ", code = "struct ipv6_mreq x; (void)x;", includes = ["#include <netinet/in.h>"]),
    checks.AC_TRY_COMPILE(define = "HAVE_STRUCT_MFXCONFIGINTERFACE", code = "struct mfxConfigInterface x; (void)x;", includes = ["#include <vpl/mfxdefs.h>", "#include <vpl/mfxvideo.h>"]),
    checks.AC_TRY_COMPILE(define = "HAVE_STRUCT_MSGHDR_MSG_FLAGS", code = "const void *p = &((struct msghdr *)0)->msg_flags; (void)p;", includes = ["#include <sys/socket.h>"]),
    checks.AC_TRY_COMPILE(define = "HAVE_STRUCT_POLLFD", code = "struct pollfd x; (void)x;", includes = ["#include <poll.h>"]),
    checks.AC_TRY_COMPILE(define = "HAVE_STRUCT_RUSAGE_RU_MAXRSS", code = "const void *p = &((struct rusage *)0)->ru_maxrss; (void)p;", includes = ["#include <sys/time.h>", "#include <sys/resource.h>"]),
    checks.AC_TRY_COMPILE(define = "HAVE_STRUCT_SCTP_EVENT_SUBSCRIBE", code = "struct sctp_event_subscribe x; (void)x;", includes = ["#include <netinet/sctp.h>"]),
    checks.AC_TRY_COMPILE(define = "HAVE_STRUCT_SOCKADDR_IN6", code = "struct sockaddr_in6 x; (void)x;", includes = ["#include <netinet/in.h>"]),
    checks.AC_TRY_COMPILE(define = "HAVE_STRUCT_SOCKADDR_SA_LEN", code = "const void *p = &((struct sockaddr *)0)->sa_len; (void)p;", includes = ["#include <sys/types.h>", "#include <sys/socket.h>"]),
    checks.AC_TRY_COMPILE(define = "HAVE_STRUCT_SOCKADDR_STORAGE", code = "struct sockaddr_storage x; (void)x;", includes = ["#include <sys/types.h>", "#include <sys/socket.h>"]),
    checks.AC_TRY_COMPILE(define = "HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC", code = "const void *p = &((struct stat *)0)->st_mtim.tv_nsec; (void)p;", includes = ["#include <sys/stat.h>"]),
    checks.AC_TRY_COMPILE(define = "HAVE_STRUCT_V4L2_FRMIVALENUM_DISCRETE", code = "struct v4l2_frmsizeenum vfse; vfse.discrete.width = 0; (void)vfse;", includes = ["#include <linux/videodev2.h>"]),
    checks.AC_TRY_COMPILE(define = "HAVE_KCMVIDEOCODECTYPE_HEVC", code = "int x = (int)kCMVideoCodecType_HEVC; (void)x;", includes = ["#include <CoreMedia/CMFormatDescription.h>"]),
    checks.AC_TRY_COMPILE(define = "HAVE_KCMVIDEOCODECTYPE_HEVCWITHALPHA", code = "int x = (int)kCMVideoCodecType_HEVCWithAlpha; (void)x;", includes = ["#include <CoreMedia/CMFormatDescription.h>"]),
    checks.AC_TRY_COMPILE(define = "HAVE_KCMVIDEOCODECTYPE_VP9", code = "int x = (int)kCMVideoCodecType_VP9; (void)x;", includes = ["#include <CoreMedia/CMFormatDescription.h>"]),
    checks.AC_TRY_COMPILE(define = "HAVE_KCVIMAGEBUFFERCOLORPRIMARIES_ITU_R_2020", code = "int x = (int)kCVImageBufferColorPrimaries_ITU_R_2020; (void)x;", includes = ["#include <CoreVideo/CVImageBuffer.h>"]),
    checks.AC_TRY_COMPILE(define = "HAVE_KCVIMAGEBUFFERTRANSFERFUNCTION_ITU_R_2020", code = "int x = (int)kCVImageBufferTransferFunction_ITU_R_2020; (void)x;", includes = ["#include <CoreVideo/CVImageBuffer.h>"]),
    checks.AC_TRY_COMPILE(define = "HAVE_KCVIMAGEBUFFERTRANSFERFUNCTION_ITU_R_2100_HLG", code = "int x = (int)kCVImageBufferTransferFunction_ITU_R_2100_HLG; (void)x;", includes = ["#include <CoreVideo/CVImageBuffer.h>"]),
    checks.AC_TRY_COMPILE(define = "HAVE_KCVIMAGEBUFFERTRANSFERFUNCTION_LINEAR", code = "int x = (int)kCVImageBufferTransferFunction_Linear; (void)x;", includes = ["#include <CoreVideo/CVImageBuffer.h>"]),
    checks.AC_TRY_COMPILE(define = "HAVE_KCVIMAGEBUFFERTRANSFERFUNCTION_SMPTE_ST_2084_PQ", code = "int x = (int)kCVImageBufferTransferFunction_SMPTE_ST_2084_PQ; (void)x;", includes = ["#include <CoreVideo/CVImageBuffer.h>"]),
    checks.AC_TRY_COMPILE(define = "HAVE_KCVIMAGEBUFFERTRANSFERFUNCTION_SMPTE_ST_428_1", code = "int x = (int)kCVImageBufferTransferFunction_SMPTE_ST_428_1; (void)x;", includes = ["#include <CoreVideo/CVImageBuffer.h>"]),
    checks.AC_TRY_COMPILE(define = "HAVE_KCVIMAGEBUFFERYCBCRMATRIX_ITU_R_2020", code = "int x = (int)kCVImageBufferYCbCrMatrix_ITU_R_2020; (void)x;", includes = ["#include <CoreVideo/CVImageBuffer.h>"]),
    checks.AC_TRY_COMPILE(define = "HAVE_KCVPIXELFORMATTYPE_420YPCBCR10BIPLANARVIDEORANGE", code = "int x = (int)kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange; (void)x;", includes = ["#include <CoreVideo/CVPixelBuffer.h>"]),
    checks.AC_TRY_COMPILE(define = "HAVE_KCVPIXELFORMATTYPE_422YPCBCR10BIPLANARVIDEORANGE", code = "int x = (int)kCVPixelFormatType_422YpCbCr10BiPlanarVideoRange; (void)x;", includes = ["#include <CoreVideo/CVPixelBuffer.h>"]),
    checks.AC_TRY_COMPILE(define = "HAVE_KCVPIXELFORMATTYPE_422YPCBCR16BIPLANARVIDEORANGE", code = "int x = (int)kCVPixelFormatType_422YpCbCr16BiPlanarVideoRange; (void)x;", includes = ["#include <CoreVideo/CVPixelBuffer.h>"]),
    checks.AC_TRY_COMPILE(define = "HAVE_KCVPIXELFORMATTYPE_422YPCBCR8BIPLANARVIDEORANGE", code = "int x = (int)kCVPixelFormatType_422YpCbCr8BiPlanarVideoRange; (void)x;", includes = ["#include <CoreVideo/CVPixelBuffer.h>"]),
    checks.AC_TRY_COMPILE(define = "HAVE_KCVPIXELFORMATTYPE_444YPCBCR10BIPLANARVIDEORANGE", code = "int x = (int)kCVPixelFormatType_444YpCbCr10BiPlanarVideoRange; (void)x;", includes = ["#include <CoreVideo/CVPixelBuffer.h>"]),
    checks.AC_TRY_COMPILE(define = "HAVE_KCVPIXELFORMATTYPE_444YPCBCR16BIPLANARVIDEORANGE", code = "int x = (int)kCVPixelFormatType_444YpCbCr16BiPlanarVideoRange; (void)x;", includes = ["#include <CoreVideo/CVPixelBuffer.h>"]),
    checks.AC_TRY_COMPILE(define = "HAVE_KCVPIXELFORMATTYPE_444YPCBCR8BIPLANARVIDEORANGE", code = "int x = (int)kCVPixelFormatType_444YpCbCr8BiPlanarVideoRange; (void)x;", includes = ["#include <CoreVideo/CVPixelBuffer.h>"]),

    # ========== ISA extension checks (ARCH_EXT_LIST) ==========
    checks.AC_TRY_COMPILE(name = "ac_cv_armv5te_inline", define = "HAVE_ARMV5TE_INLINE", code = "#if !(defined(__arm__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"qadd r0, r0, r0\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_ARMV5TE_EXTERNAL", code = "#if !(defined(__arm__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"qadd r0, r0, r0\"); }"),
    checks.AC_DEFINE("HAVE_ARMV5TE", condition = "ac_cv_armv5te_inline", if_true = "1", if_false = "0"),
    checks.AC_TRY_COMPILE(name = "ac_cv_armv6_inline", define = "HAVE_ARMV6_INLINE", code = "#if !(defined(__arm__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"sadd16 r0, r0, r0\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_ARMV6_EXTERNAL", code = "#if !(defined(__arm__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"sadd16 r0, r0, r0\"); }"),
    checks.AC_DEFINE("HAVE_ARMV6", condition = "ac_cv_armv6_inline", if_true = "1", if_false = "0"),
    checks.AC_TRY_COMPILE(name = "ac_cv_armv6t2_inline", define = "HAVE_ARMV6T2_INLINE", code = "#if !(defined(__arm__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"movt r0, #0\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_ARMV6T2_EXTERNAL", code = "#if !(defined(__arm__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"movt r0, #0\"); }"),
    checks.AC_DEFINE("HAVE_ARMV6T2", condition = "ac_cv_armv6t2_inline", if_true = "1", if_false = "0"),
    checks.AC_TRY_COMPILE(name = "ac_cv_armv8_inline", define = "HAVE_ARMV8_INLINE", code = "#if !(defined(__aarch64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"prfm pldl1strm, [x0]\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_ARMV8_EXTERNAL", code = "#if !(defined(__aarch64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"prfm pldl1strm, [x0]\"); }"),
    checks.AC_DEFINE("HAVE_ARMV8", condition = "ac_cv_armv8_inline", if_true = "1", if_false = "0"),
    checks.AC_TRY_COMPILE(name = "ac_cv_dotprod_inline", define = "HAVE_DOTPROD_INLINE", code = "#if !(defined(__aarch64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"udot v0.4s, v0.16b, v0.16b\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_DOTPROD_EXTERNAL", code = "#if !(defined(__aarch64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"udot v0.4s, v0.16b, v0.16b\"); }"),
    checks.AC_DEFINE("HAVE_DOTPROD", condition = "ac_cv_dotprod_inline", if_true = "1", if_false = "0"),
    checks.AC_TRY_COMPILE(name = "ac_cv_i8mm_inline", define = "HAVE_I8MM_INLINE", code = "#if !(defined(__aarch64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"usdot v0.4s, v0.16b, v0.16b\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_I8MM_EXTERNAL", code = "#if !(defined(__aarch64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"usdot v0.4s, v0.16b, v0.16b\"); }"),
    checks.AC_DEFINE("HAVE_I8MM", condition = "ac_cv_i8mm_inline", if_true = "1", if_false = "0"),
    checks.AC_TRY_COMPILE(name = "ac_cv_neon_inline", define = "HAVE_NEON_INLINE", code = "#if !(defined(__aarch64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"ext v0.8B, v0.8B, v1.8B, #1\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_NEON_EXTERNAL", code = "#if !(defined(__aarch64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"ext v0.8B, v0.8B, v1.8B, #1\"); }"),
    checks.AC_DEFINE("HAVE_NEON", condition = "ac_cv_neon_inline", if_true = "1", if_false = "0"),
    checks.AC_TRY_COMPILE(name = "ac_cv_vfp_inline", define = "HAVE_VFP_INLINE", code = "#if !(defined(__arm__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"fadds s0, s0, s0\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_VFP_EXTERNAL", code = "#if !(defined(__arm__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"fadds s0, s0, s0\"); }"),
    checks.AC_DEFINE("HAVE_VFP", condition = "ac_cv_vfp_inline", if_true = "1", if_false = "0"),
    checks.AC_TRY_COMPILE(name = "ac_cv_vfpv3_inline", define = "HAVE_VFPV3_INLINE", code = "#if !(defined(__arm__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"vmov.f32 s0, #1.0\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_VFPV3_EXTERNAL", code = "#if !(defined(__arm__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"vmov.f32 s0, #1.0\"); }"),
    checks.AC_DEFINE("HAVE_VFPV3", condition = "ac_cv_vfpv3_inline", if_true = "1", if_false = "0"),
    checks.AC_TRY_COMPILE(name = "ac_cv_setend_inline", define = "HAVE_SETEND_INLINE", code = "#if !(defined(__arm__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"setend be\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_SETEND_EXTERNAL", code = "#if !(defined(__arm__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"setend be\"); }"),
    checks.AC_DEFINE("HAVE_SETEND", condition = "ac_cv_setend_inline", if_true = "1", if_false = "0"),
    checks.AC_TRY_COMPILE(name = "ac_cv_altivec_inline", define = "HAVE_ALTIVEC_INLINE", code = "#if !(defined(__powerpc__) || defined(__powerpc64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\".long 0x10000484\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_ALTIVEC_EXTERNAL", code = "#if !(defined(__powerpc__) || defined(__powerpc64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\".long 0x10000484\"); }"),
    checks.AC_DEFINE("HAVE_ALTIVEC", condition = "ac_cv_altivec_inline", if_true = "1", if_false = "0"),
    checks.AC_TRY_COMPILE(name = "ac_cv_dcbzl_inline", define = "HAVE_DCBZL_INLINE", code = "#if !(defined(__powerpc__) || defined(__powerpc64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"dcbzl 0, %r0\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_DCBZL_EXTERNAL", code = "#if !(defined(__powerpc__) || defined(__powerpc64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"dcbzl 0, %r0\"); }"),
    checks.AC_DEFINE("HAVE_DCBZL", condition = "ac_cv_dcbzl_inline", if_true = "1", if_false = "0"),
    checks.AC_TRY_COMPILE(name = "ac_cv_ldbrx_inline", define = "HAVE_LDBRX_INLINE", code = "#if !(defined(__powerpc__) || defined(__powerpc64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"ldbrx 0, 0, 0\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_LDBRX_EXTERNAL", code = "#if !(defined(__powerpc__) || defined(__powerpc64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"ldbrx 0, 0, 0\"); }"),
    checks.AC_DEFINE("HAVE_LDBRX", condition = "ac_cv_ldbrx_inline", if_true = "1", if_false = "0"),
    checks.AC_TRY_COMPILE(name = "ac_cv_power8_inline", define = "HAVE_POWER8_INLINE", code = "#if !(defined(__powerpc__) || defined(__powerpc64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"vaddudm %v0, %v0, %v0\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_POWER8_EXTERNAL", code = "#if !(defined(__powerpc__) || defined(__powerpc64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"vaddudm %v0, %v0, %v0\"); }"),
    checks.AC_DEFINE("HAVE_POWER8", condition = "ac_cv_power8_inline", if_true = "1", if_false = "0"),
    checks.AC_TRY_COMPILE(name = "ac_cv_ppc4xx_inline", define = "HAVE_PPC4XX_INLINE", code = "#if !(defined(__powerpc__) || defined(__powerpc64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"maclhw %r10, %r11, %r12\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_PPC4XX_EXTERNAL", code = "#if !(defined(__powerpc__) || defined(__powerpc64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"maclhw %r10, %r11, %r12\"); }"),
    checks.AC_DEFINE("HAVE_PPC4XX", condition = "ac_cv_ppc4xx_inline", if_true = "1", if_false = "0"),
    checks.AC_TRY_COMPILE(name = "ac_cv_vsx_inline", define = "HAVE_VSX_INLINE", code = "#if !(defined(__powerpc__) || defined(__powerpc64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"xvmaxsp %vs0, %vs0, %vs0\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_VSX_EXTERNAL", code = "#if !(defined(__powerpc__) || defined(__powerpc64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"xvmaxsp %vs0, %vs0, %vs0\"); }"),
    checks.AC_DEFINE("HAVE_VSX", condition = "ac_cv_vsx_inline", if_true = "1", if_false = "0"),
    checks.AC_TRY_COMPILE(name = "ac_cv_rv_inline", define = "HAVE_RV_INLINE", code = "#if !(defined(__riscv))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\".option arch, +zbb\\nrev8 t0, t1\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_RV_EXTERNAL", code = "#if !(defined(__riscv))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\".option arch, +zbb\\nrev8 t0, t1\"); }"),
    checks.AC_DEFINE("HAVE_RV", condition = "ac_cv_rv_inline", if_true = "1", if_false = "0"),
    checks.AC_TRY_COMPILE(name = "ac_cv_rvv_inline", define = "HAVE_RVV_INLINE", code = "#if !(defined(__riscv))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\".option arch, +v\\nvsetivli zero, 0, e8, m1, ta, ma\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_RVV_EXTERNAL", code = "#if !(defined(__riscv))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\".option arch, +v\\nvsetivli zero, 0, e8, m1, ta, ma\"); }"),
    checks.AC_DEFINE("HAVE_RVV", condition = "ac_cv_rvv_inline", if_true = "1", if_false = "0"),
    checks.AC_TRY_COMPILE(name = "ac_cv_rv_zicbop_inline", define = "HAVE_RV_ZICBOP_INLINE", code = "#if !(defined(__riscv))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\".option arch, +zicbop\\nprefetch.r 64(a0)\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_RV_ZICBOP_EXTERNAL", code = "#if !(defined(__riscv))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\".option arch, +zicbop\\nprefetch.r 64(a0)\"); }"),
    checks.AC_DEFINE("HAVE_RV_ZICBOP", condition = "ac_cv_rv_zicbop_inline", if_true = "1", if_false = "0"),
    checks.AC_TRY_COMPILE(name = "ac_cv_rv_zvbb_inline", define = "HAVE_RV_ZVBB_INLINE", code = "#if !(defined(__riscv))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\".option arch, +zvbb\\nvclz.v v0, v8\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_RV_ZVBB_EXTERNAL", code = "#if !(defined(__riscv))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\".option arch, +zvbb\\nvclz.v v0, v8\"); }"),
    checks.AC_DEFINE("HAVE_RV_ZVBB", condition = "ac_cv_rv_zvbb_inline", if_true = "1", if_false = "0"),
    checks.AC_TRY_COMPILE(name = "ac_cv_aesni_inline", define = "HAVE_AESNI_INLINE", code = "#if !(defined(__i386__) || defined(__x86_64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"aesenc %xmm0, %xmm0\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_AESNI_EXTERNAL", code = "#if !(defined(__i386__) || defined(__x86_64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"aesenc %xmm0, %xmm0\"); }"),
    checks.AC_DEFINE("HAVE_AESNI", condition = "ac_cv_aesni_inline", if_true = "1", if_false = "0"),
    checks.AC_TRY_COMPILE(name = "ac_cv_amd3dnow_inline", define = "HAVE_AMD3DNOW_INLINE", code = "#if !(defined(__i386__) || defined(__x86_64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"pfadd %mm0, %mm1\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_AMD3DNOW_EXTERNAL", code = "#if !(defined(__i386__) || defined(__x86_64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"pfadd %mm0, %mm1\"); }"),
    checks.AC_DEFINE("HAVE_AMD3DNOW", condition = "ac_cv_amd3dnow_inline", if_true = "1", if_false = "0"),
    checks.AC_TRY_COMPILE(name = "ac_cv_amd3dnowext_inline", define = "HAVE_AMD3DNOWEXT_INLINE", code = "#if !(defined(__i386__) || defined(__x86_64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"pfnacc %mm0, %mm1\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_AMD3DNOWEXT_EXTERNAL", code = "#if !(defined(__i386__) || defined(__x86_64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"pfnacc %mm0, %mm1\"); }"),
    checks.AC_DEFINE("HAVE_AMD3DNOWEXT", condition = "ac_cv_amd3dnowext_inline", if_true = "1", if_false = "0"),
    checks.AC_TRY_COMPILE(name = "ac_cv_avx_inline", define = "HAVE_AVX_INLINE", code = "#if !(defined(__i386__) || defined(__x86_64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"vextractf128 $0, %ymm0, %xmm0\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_AVX_EXTERNAL", code = "#if !(defined(__i386__) || defined(__x86_64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"vextractf128 $0, %ymm0, %xmm0\"); }"),
    checks.AC_DEFINE("HAVE_AVX", condition = "ac_cv_avx_inline", if_true = "1", if_false = "0"),
    checks.AC_TRY_COMPILE(name = "ac_cv_avx2_inline", define = "HAVE_AVX2_INLINE", code = "#if !(defined(__i386__) || defined(__x86_64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"vextracti128 $0, %ymm0, %xmm0\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_AVX2_EXTERNAL", code = "#if !(defined(__i386__) || defined(__x86_64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"vextracti128 $0, %ymm0, %xmm0\"); }"),
    checks.AC_DEFINE("HAVE_AVX2", condition = "ac_cv_avx2_inline", if_true = "1", if_false = "0"),
    checks.AC_TRY_COMPILE(name = "ac_cv_avx512_inline", define = "HAVE_AVX512_INLINE", code = "#if !(defined(__i386__) || defined(__x86_64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"vmovdqa32 %zmm0, %zmm0\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_AVX512_EXTERNAL", code = "#if !(defined(__i386__) || defined(__x86_64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"vmovdqa32 %zmm0, %zmm0\"); }"),
    checks.AC_DEFINE("HAVE_AVX512", condition = "ac_cv_avx512_inline", if_true = "1", if_false = "0"),
    checks.AC_TRY_COMPILE(name = "ac_cv_avx512icl_inline", define = "HAVE_AVX512ICL_INLINE", code = "#if !(defined(__i386__) || defined(__x86_64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"vpdpwssds %zmm0, %zmm1, %zmm2\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_AVX512ICL_EXTERNAL", code = "#if !(defined(__i386__) || defined(__x86_64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"vpdpwssds %zmm0, %zmm1, %zmm2\"); }"),
    checks.AC_DEFINE("HAVE_AVX512ICL", condition = "ac_cv_avx512icl_inline", if_true = "1", if_false = "0"),
    checks.AC_TRY_COMPILE(name = "ac_cv_fma3_inline", define = "HAVE_FMA3_INLINE", code = "#if !(defined(__i386__) || defined(__x86_64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"vfmadd132ps %ymm0, %ymm1, %ymm2\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_FMA3_EXTERNAL", code = "#if !(defined(__i386__) || defined(__x86_64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"vfmadd132ps %ymm0, %ymm1, %ymm2\"); }"),
    checks.AC_DEFINE("HAVE_FMA3", condition = "ac_cv_fma3_inline", if_true = "1", if_false = "0"),
    checks.AC_TRY_COMPILE(name = "ac_cv_fma4_inline", define = "HAVE_FMA4_INLINE", code = "#if !(defined(__i386__) || defined(__x86_64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"vfmaddps %ymm0, %ymm1, %ymm2, %ymm3\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_FMA4_EXTERNAL", code = "#if !(defined(__i386__) || defined(__x86_64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"vfmaddps %ymm0, %ymm1, %ymm2, %ymm3\"); }"),
    checks.AC_DEFINE("HAVE_FMA4", condition = "ac_cv_fma4_inline", if_true = "1", if_false = "0"),
    checks.AC_TRY_COMPILE(name = "ac_cv_mmx_inline", define = "HAVE_MMX_INLINE", code = "#if !(defined(__i386__) || defined(__x86_64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"emms\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_MMX_EXTERNAL", code = "#if !(defined(__i386__) || defined(__x86_64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"emms\"); }"),
    checks.AC_DEFINE("HAVE_MMX", condition = "ac_cv_mmx_inline", if_true = "1", if_false = "0"),
    checks.AC_TRY_COMPILE(name = "ac_cv_mmxext_inline", define = "HAVE_MMXEXT_INLINE", code = "#if !(defined(__i386__) || defined(__x86_64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"pmaxub %mm0, %mm1\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_MMXEXT_EXTERNAL", code = "#if !(defined(__i386__) || defined(__x86_64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"pmaxub %mm0, %mm1\"); }"),
    checks.AC_DEFINE("HAVE_MMXEXT", condition = "ac_cv_mmxext_inline", if_true = "1", if_false = "0"),
    checks.AC_TRY_COMPILE(name = "ac_cv_sse_inline", define = "HAVE_SSE_INLINE", code = "#if !(defined(__i386__) || defined(__x86_64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"xorps %xmm0, %xmm0\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_SSE_EXTERNAL", code = "#if !(defined(__i386__) || defined(__x86_64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"xorps %xmm0, %xmm0\"); }"),
    checks.AC_DEFINE("HAVE_SSE", condition = "ac_cv_sse_inline", if_true = "1", if_false = "0"),
    checks.AC_TRY_COMPILE(name = "ac_cv_sse2_inline", define = "HAVE_SSE2_INLINE", code = "#if !(defined(__i386__) || defined(__x86_64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"pslld $7, %xmm0\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_SSE2_EXTERNAL", code = "#if !(defined(__i386__) || defined(__x86_64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"pslld $7, %xmm0\"); }"),
    checks.AC_DEFINE("HAVE_SSE2", condition = "ac_cv_sse2_inline", if_true = "1", if_false = "0"),
    checks.AC_TRY_COMPILE(name = "ac_cv_sse3_inline", define = "HAVE_SSE3_INLINE", code = "#if !(defined(__i386__) || defined(__x86_64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"addsubps %xmm0, %xmm1\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_SSE3_EXTERNAL", code = "#if !(defined(__i386__) || defined(__x86_64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"addsubps %xmm0, %xmm1\"); }"),
    checks.AC_DEFINE("HAVE_SSE3", condition = "ac_cv_sse3_inline", if_true = "1", if_false = "0"),
    checks.AC_TRY_COMPILE(name = "ac_cv_sse4_inline", define = "HAVE_SSE4_INLINE", code = "#if !(defined(__i386__) || defined(__x86_64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"pblendvb %xmm0, %xmm1\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_SSE4_EXTERNAL", code = "#if !(defined(__i386__) || defined(__x86_64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"pblendvb %xmm0, %xmm1\"); }"),
    checks.AC_DEFINE("HAVE_SSE4", condition = "ac_cv_sse4_inline", if_true = "1", if_false = "0"),
    checks.AC_TRY_COMPILE(name = "ac_cv_sse42_inline", define = "HAVE_SSE42_INLINE", code = "#if !(defined(__i386__) || defined(__x86_64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"crc32 %eax, %eax\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_SSE42_EXTERNAL", code = "#if !(defined(__i386__) || defined(__x86_64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"crc32 %eax, %eax\"); }"),
    checks.AC_DEFINE("HAVE_SSE42", condition = "ac_cv_sse42_inline", if_true = "1", if_false = "0"),
    checks.AC_TRY_COMPILE(name = "ac_cv_ssse3_inline", define = "HAVE_SSSE3_INLINE", code = "#if !(defined(__i386__) || defined(__x86_64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"pabsw %xmm0, %xmm0\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_SSSE3_EXTERNAL", code = "#if !(defined(__i386__) || defined(__x86_64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"pabsw %xmm0, %xmm0\"); }"),
    checks.AC_DEFINE("HAVE_SSSE3", condition = "ac_cv_ssse3_inline", if_true = "1", if_false = "0"),
    checks.AC_TRY_COMPILE(name = "ac_cv_xop_inline", define = "HAVE_XOP_INLINE", code = "#if !(defined(__i386__) || defined(__x86_64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"vpmacsdd %xmm0, %xmm1, %xmm2, %xmm3\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_XOP_EXTERNAL", code = "#if !(defined(__i386__) || defined(__x86_64__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"vpmacsdd %xmm0, %xmm1, %xmm2, %xmm3\"); }"),
    checks.AC_DEFINE("HAVE_XOP", condition = "ac_cv_xop_inline", if_true = "1", if_false = "0"),
    checks.AC_TRY_COMPILE(name = "ac_cv_i686_inline", define = "HAVE_I686_INLINE", code = "#if !(defined(__i386__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"cmovz %eax, %ebx\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_I686_EXTERNAL", code = "#if !(defined(__i386__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"cmovz %eax, %ebx\"); }"),
    checks.AC_DEFINE("HAVE_I686", condition = "ac_cv_i686_inline", if_true = "1", if_false = "0"),
    checks.AC_TRY_COMPILE(name = "ac_cv_mipsfpu_inline", define = "HAVE_MIPSFPU_INLINE", code = "#if !(defined(__mips__) || defined(__mips64))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"cvt.d.l $f0, $f2\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_MIPSFPU_EXTERNAL", code = "#if !(defined(__mips__) || defined(__mips64))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"cvt.d.l $f0, $f2\"); }"),
    checks.AC_DEFINE("HAVE_MIPSFPU", condition = "ac_cv_mipsfpu_inline", if_true = "1", if_false = "0"),
    checks.AC_TRY_COMPILE(name = "ac_cv_mips32r2_inline", define = "HAVE_MIPS32R2_INLINE", code = "#if !(defined(__mips__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"ext $0, $0, 0, 1\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_MIPS32R2_EXTERNAL", code = "#if !(defined(__mips__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"ext $0, $0, 0, 1\"); }"),
    checks.AC_DEFINE("HAVE_MIPS32R2", condition = "ac_cv_mips32r2_inline", if_true = "1", if_false = "0"),
    checks.AC_TRY_COMPILE(name = "ac_cv_mips32r5_inline", define = "HAVE_MIPS32R5_INLINE", code = "#if !(defined(__mips__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"eretnc\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_MIPS32R5_EXTERNAL", code = "#if !(defined(__mips__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"eretnc\"); }"),
    checks.AC_DEFINE("HAVE_MIPS32R5", condition = "ac_cv_mips32r5_inline", if_true = "1", if_false = "0"),
    checks.AC_TRY_COMPILE(name = "ac_cv_mips64r2_inline", define = "HAVE_MIPS64R2_INLINE", code = "#if !(defined(__mips64))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"dext $0, $0, 0, 1\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_MIPS64R2_EXTERNAL", code = "#if !(defined(__mips64))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"dext $0, $0, 0, 1\"); }"),
    checks.AC_DEFINE("HAVE_MIPS64R2", condition = "ac_cv_mips64r2_inline", if_true = "1", if_false = "0"),
    checks.AC_TRY_COMPILE(name = "ac_cv_mips32r6_inline", define = "HAVE_MIPS32R6_INLINE", code = "#if !(defined(__mips__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"aui $0, $0, 0\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_MIPS32R6_EXTERNAL", code = "#if !(defined(__mips__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"aui $0, $0, 0\"); }"),
    checks.AC_DEFINE("HAVE_MIPS32R6", condition = "ac_cv_mips32r6_inline", if_true = "1", if_false = "0"),
    checks.AC_TRY_COMPILE(name = "ac_cv_mips64r6_inline", define = "HAVE_MIPS64R6_INLINE", code = "#if !(defined(__mips64))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"dlsa $0, $0, $0, 1\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_MIPS64R6_EXTERNAL", code = "#if !(defined(__mips64))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"dlsa $0, $0, $0, 1\"); }"),
    checks.AC_DEFINE("HAVE_MIPS64R6", condition = "ac_cv_mips64r6_inline", if_true = "1", if_false = "0"),
    checks.AC_TRY_COMPILE(name = "ac_cv_mipsdsp_inline", define = "HAVE_MIPSDSP_INLINE", code = "#if !(defined(__mips__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"addu.qb $t0, $t1, $t2\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_MIPSDSP_EXTERNAL", code = "#if !(defined(__mips__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"addu.qb $t0, $t1, $t2\"); }"),
    checks.AC_DEFINE("HAVE_MIPSDSP", condition = "ac_cv_mipsdsp_inline", if_true = "1", if_false = "0"),
    checks.AC_TRY_COMPILE(name = "ac_cv_mipsdspr2_inline", define = "HAVE_MIPSDSPR2_INLINE", code = "#if !(defined(__mips__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"absq_s.qb $t0, $t1\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_MIPSDSPR2_EXTERNAL", code = "#if !(defined(__mips__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"absq_s.qb $t0, $t1\"); }"),
    checks.AC_DEFINE("HAVE_MIPSDSPR2", condition = "ac_cv_mipsdspr2_inline", if_true = "1", if_false = "0"),
    checks.AC_TRY_COMPILE(name = "ac_cv_msa_inline", define = "HAVE_MSA_INLINE", code = "#if !(defined(__mips__) || defined(__mips64))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"addvi.b $w0, $w1, 1\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_MSA_EXTERNAL", code = "#if !(defined(__mips__) || defined(__mips64))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"addvi.b $w0, $w1, 1\"); }"),
    checks.AC_DEFINE("HAVE_MSA", condition = "ac_cv_msa_inline", if_true = "1", if_false = "0"),
    checks.AC_DEFINE("HAVE_LOONGSON2", "0"),
    checks.AC_DEFINE("HAVE_LOONGSON2_EXTERNAL", "0"),
    checks.AC_DEFINE("HAVE_LOONGSON2_INLINE", "0"),
    checks.AC_DEFINE("HAVE_LOONGSON3", "0"),
    checks.AC_DEFINE("HAVE_LOONGSON3_EXTERNAL", "0"),
    checks.AC_DEFINE("HAVE_LOONGSON3_INLINE", "0"),
    checks.AC_DEFINE("HAVE_MMI", "0"),
    checks.AC_DEFINE("HAVE_MMI_EXTERNAL", "0"),
    checks.AC_DEFINE("HAVE_MMI_INLINE", "0"),
    checks.AC_TRY_COMPILE(name = "ac_cv_lsx_inline", define = "HAVE_LSX_INLINE", code = "#if !(defined(__loongarch__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"vadd.b $vr0, $vr1, $vr2\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_LSX_EXTERNAL", code = "#if !(defined(__loongarch__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"vadd.b $vr0, $vr1, $vr2\"); }"),
    checks.AC_DEFINE("HAVE_LSX", condition = "ac_cv_lsx_inline", if_true = "1", if_false = "0"),
    checks.AC_TRY_COMPILE(name = "ac_cv_lasx_inline", define = "HAVE_LASX_INLINE", code = "#if !(defined(__loongarch__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"xvadd.b $xr0, $xr1, $xr2\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_LASX_EXTERNAL", code = "#if !(defined(__loongarch__))\n#error wrong arch\n#endif\nvoid foo(void){ __asm__ volatile(\"xvadd.b $xr0, $xr1, $xr2\"); }"),
    checks.AC_DEFINE("HAVE_LASX", condition = "ac_cv_lasx_inline", if_true = "1", if_false = "0"),
    # ========== Architecture features (ARCH_FEATURES) ==========
    checks.AC_TRY_COMPILE(define = "HAVE_ALIGNED_STACK", code = "#if !defined(__x86_64__) && !defined(__aarch64__)\n#error\n#endif"),
    checks.AC_TRY_COMPILE(name = "ac_cv_feat_fast_64bit", define = "HAVE_FAST_64BIT", code = "#if !(defined(__x86_64__) || defined(__aarch64__) || defined(__powerpc64__) || defined(__mips64) || defined(__loongarch64__) || (defined(__riscv) && __riscv_xlen == 64))\n#error\n#endif"),
    checks.AC_TRY_COMPILE(define = "HAVE_FAST_CLZ", code = "#if !(defined(__x86_64__) || defined(__aarch64__) || defined(__i386__) || defined(__arm__) || defined(__mips__) || defined(__powerpc__) || defined(__loongarch__) || defined(__riscv))\n#error\n#endif"),
    checks.AC_TRY_COMPILE(define = "HAVE_FAST_CMOV", code = "#if !(defined(__x86_64__) || (defined(__i386__) && defined(__SSE2__)))\n#error\n#endif"),
    checks.AC_TRY_COMPILE(define = "HAVE_FAST_FLOAT16", code = "#if !(defined(__aarch64__) || defined(__arm__) || (defined(__x86_64__) && defined(__F16C__)))\n#error\n#endif"),
    checks.AC_TRY_COMPILE(define = "HAVE_LOCAL_ALIGNED", code = "int x = 0; (void)x;"),
    checks.AC_TRY_COMPILE(define = "HAVE_SIMD_ALIGN_16", code = "#if !(defined(__x86_64__) || defined(__aarch64__) || defined(__arm__) || defined(__powerpc__) || defined(__mips__))\n#error\n#endif"),
    checks.AC_DEFINE("HAVE_SIMD_ALIGN_32", condition = "ac_cv_avx_inline", if_true = "1", if_false = "0"),
    checks.AC_DEFINE("HAVE_SIMD_ALIGN_64", condition = "ac_cv_avx512_inline", if_true = "1", if_false = "0"),

    # ========== Builtin checks (BUILTIN_LIST) ==========
    checks.AC_TRY_LINK(define = "HAVE_MEMORYBARRIER", code = "MemoryBarrier()", includes = ["#include <windows.h>"]),
    checks.AC_TRY_LINK(define = "HAVE_MM_EMPTY", code = "_mm_empty()", includes = ["#include <mmintrin.h>"]),
    checks.AC_TRY_LINK(define = "HAVE_RDTSC", code = "__rdtsc()", includes = ["#include <intrin.h>"]),
    checks.AC_CHECK_LIB("pthread", "sem_timedwait", define = "HAVE_SEM_TIMEDWAIT"),

    # ========== Intrinsics checks (INTRINSICS_LIST) ==========
    checks.AC_TRY_COMPILE(define = "HAVE_INTRINSICS_NEON", code = "int32x4_t test = vdupq_n_s32(0); (void)test;", includes = ["#include <arm_neon.h>"]),
    checks.AC_TRY_COMPILE(define = "HAVE_INTRINSICS_SSE2", code = "__m128i test = _mm_setzero_si128(); (void)test;", includes = ["#include <emmintrin.h>"]),

    # ========== Toolchain feature checks (TOOLCHAIN_FEATURES) ==========
    checks.AC_TRY_COMPILE(define = "HAVE_AS_ARCH_DIRECTIVE", code = "void foo(void){ __asm__ volatile(\".arch armv7-a\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_AS_ARCHEXT_DOTPROD_DIRECTIVE", code = "void foo(void){ __asm__ volatile(\".arch_extension dotprod\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_AS_ARCHEXT_I8MM_DIRECTIVE", code = "void foo(void){ __asm__ volatile(\".arch_extension i8mm\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_AS_DN_DIRECTIVE", code = "void foo(void){ __asm__ volatile(\"ra .dn d0.i16\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_AS_FPU_DIRECTIVE", code = "void foo(void){ __asm__ volatile(\".fpu neon\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_AS_FUNC", code = "void foo(void){ __asm__ volatile(\".func test\n.endfunc\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_AS_OBJECT_ARCH", code = "void foo(void){ __asm__ volatile(\".object_arch armv4\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_ASM_MOD_Q", code = "void foo(void){ __asm__ volatile(\"\" :: \"q\"(0)); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_BLOCKS_EXTENSION", code = "void (^block)(void) = ^{ }; block();"),
    checks.AC_TRY_COMPILE(define = "HAVE_EBP_AVAILABLE", code = "void foo(void){ __asm__ volatile(\"\" ::: \"ebp\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_EBX_AVAILABLE", code = "void foo(void){ __asm__ volatile(\"\" ::: \"ebx\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_GNU_AS", code = "#if !defined(__GNUC__)\n#error\n#endif"),
    checks.AC_TRY_COMPILE(define = "HAVE_GNU_WINDRES", code = "#if !defined(_WIN32)\n#error\n#endif"),
    checks.AC_TRY_COMPILE(define = "HAVE_IBM_ASM", code = "void foo(void){ __asm__ volatile(\"add 0, 0, 0\"); }"),
    checks.AC_DEFINE("HAVE_INLINE_ASM_DIRECT_SYMBOL_REFS", "0"),
    checks.AC_TRY_COMPILE(define = "HAVE_INLINE_ASM_LABELS", code = "void foo(void){ __asm__ volatile(\"1:\n\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_INLINE_ASM_NONLOCAL_LABELS", code = "void foo(void){ __asm__ volatile(\"Label:\n\"); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_PRAGMA_DEPRECATED", code = "_Pragma(\"GCC diagnostic push\");"),
    checks.AC_TRY_COMPILE(define = "HAVE_RSYNC_CONTIMEOUT", code = "#error not a compile check"),
    checks.AC_TRY_COMPILE(define = "HAVE_SYMVER_ASM_LABEL", code = "void ff_foo(void) __asm__ (\"av_foo@VERSION\"); void ff_foo(void) {}"),
    checks.AC_TRY_COMPILE(name = "ac_cv_tc_symver_gnu_asm", define = "HAVE_SYMVER_GNU_ASM", code = "__asm__(\".symver ff_foo,av_foo@VERSION\"); void ff_foo(void) {}"),
    checks.AC_TRY_COMPILE(define = "HAVE_VFP_ARGS", code = "#if !defined(__ARM_PCS_VFP)\n#error\n#endif"),
    checks.AC_TRY_COMPILE(define = "HAVE_XFORM_ASM", code = "void foo(void){ __asm__ volatile(\"lwzx %1, %y0\" :: \"Z\"(*(int*)0), \"r\"(0)); }"),
    checks.AC_TRY_COMPILE(define = "HAVE_XMM_CLOBBERS", code = "void foo(void){ __asm__ volatile(\"\" ::: \"%xmm0\"); }"),

    # ========== Threading checks (THREADS_LIST) ==========
    checks.AC_CHECK_LIB("pthread", "pthread_create", define = "HAVE_PTHREADS"),
    checks.AC_DEFINE("HAVE_OS2THREADS", "0"),
    checks.AC_DEFINE("HAVE_W32THREADS", "0"),

    # ========== System features (SYSTEM_FEATURES) ==========
    checks.AC_TRY_COMPILE(define = "HAVE_DOS_PATHS", code = "#if defined(_WIN32)\n#else\n#error\n#endif"),
    checks.AC_TRY_COMPILE(define = "HAVE_LIBC_MSVCRT", code = "#if defined(_MSC_VER)\n#else\n#error\n#endif"),
    checks.AC_TRY_COMPILE(define = "HAVE_MMAL_PARAMETER_VIDEO_MAX_NUM_CALLBACKS", code = "#error not available"),
    checks.AC_TRY_COMPILE(define = "HAVE_SECTION_DATA_REL_RO", code = "#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__ANDROID__)\n#else\n#error\n#endif"),
    checks.AC_TRY_COMPILE(define = "HAVE_THREADS", includes = ["#include <stddef.h>"], code = "int x = 1; (void)x;"),
    checks.AC_TRY_COMPILE(define = "HAVE_UWP", code = "#error not uwp"),
    checks.AC_TRY_COMPILE(define = "HAVE_WINRT", code = "#error not winrt"),

    # ========== System libraries (SYSTEM_LIBRARIES) ==========
    checks.AC_DEFINE("HAVE_BCRYPT", "0"),
    checks.AC_DEFINE("HAVE_VAAPI_DRM", "0"),
    checks.AC_DEFINE("HAVE_VAAPI_X11", "0"),
    checks.AC_DEFINE("HAVE_VAAPI_WIN32", "0"),
    checks.AC_DEFINE("HAVE_VDPAU_X11", "0"),

    # ========== Command-line features (HAVE_LIST_CMDLINE) ==========
    checks.AC_TRY_COMPILE(define = "HAVE_INLINE_ASM", code = "void foo(void){ __asm__ volatile(\"\" :::); }"),
    checks.AC_DEFINE("HAVE_SYMVER", condition = "ac_cv_tc_symver_gnu_asm", if_true = "1", if_false = "0"),
    checks.AC_TRY_COMPILE(define = "HAVE_X86ASM", code = "#if !defined(__x86_64__)\n#error\n#endif"),

    # ========== Public features (HAVE_LIST_PUB) ==========
    checks.AC_TRY_COMPILE(define = "HAVE_BIGENDIAN", code = "#if __BYTE_ORDER__ != __ORDER_BIG_ENDIAN__\n#error\n#endif"),
    checks.AC_DEFINE("HAVE_FAST_UNALIGNED", condition = "ac_cv_feat_fast_64bit", if_true = "1", if_false = "0"),

    # ========== Misc HAVE_LIST items ==========
    checks.AC_DEFINE("HAVE_GZIP", "0"),
    checks.AC_DEFINE("HAVE_LIBDRM_GETFB2", "0"),
    checks.AC_DEFINE("HAVE_MAKEINFO", "0"),
    checks.AC_DEFINE("HAVE_MAKEINFO_HTML", "0"),
    checks.AC_DEFINE("HAVE_OPENCL_D3D11", "0"),
    checks.AC_DEFINE("HAVE_OPENCL_DRM_ARM", "0"),
    checks.AC_DEFINE("HAVE_OPENCL_DRM_BEIGNET", "0"),
    checks.AC_DEFINE("HAVE_OPENCL_DXVA2", "0"),
    checks.AC_DEFINE("HAVE_OPENCL_VAAPI_BEIGNET", "0"),
    checks.AC_DEFINE("HAVE_OPENCL_VAAPI_INTEL_MEDIA", "0"),
    checks.AC_DEFINE("HAVE_OPENCL_VIDEOTOOLBOX", "0"),
    checks.AC_DEFINE("HAVE_PERL", "0"),
    checks.AC_DEFINE("HAVE_POD2MAN", "0"),
    checks.AC_TRY_COMPILE(define = "HAVE_POSIX_IOCTL", code = "int ioctl(int, int, ...);", includes = ["#include <sys/ioctl.h>"]),
    checks.AC_DEFINE("HAVE_TEXI2HTML", "0"),
    checks.AC_DEFINE("HAVE_XMLLINT", "0"),
    checks.AC_DEFINE("HAVE_ZLIB_GZIP", "0"),
    checks.AC_DEFINE("HAVE_OPENVINO2", "0"),

    # ========== Platform-detected CONFIG_* (macOS frameworks) ==========
    checks.AC_TRY_COMPILE(define = "CONFIG_APPKIT", code = "#if !defined(__APPLE__)\n#error\n#endif"),
    checks.AC_TRY_COMPILE(define = "CONFIG_AUDIOTOOLBOX", code = "#if !defined(__APPLE__)\n#error\n#endif"),
    checks.AC_TRY_COMPILE(define = "CONFIG_AVFOUNDATION", code = "#if !defined(__APPLE__)\n#error\n#endif"),
    checks.AC_TRY_COMPILE(define = "CONFIG_COREIMAGE", code = "#if !defined(__APPLE__)\n#error\n#endif"),
    checks.AC_TRY_COMPILE(define = "CONFIG_VIDEOTOOLBOX", code = "#if !defined(__APPLE__)\n#error\n#endif"),
    checks.AC_TRY_LINK(define = "CONFIG_ICONV", code = "iconv_t x = iconv_open(\"UTF-8\", \"UTF-8\"); (void)x;", includes = ["#include <iconv.h>"]),
    checks.AC_TRY_COMPILE(define = "CONFIG_SECURETRANSPORT", code = "#if !defined(__APPLE__)\n#error\n#endif"),
]

AVCONFIG_CHECKS = [
    checks.AC_C_BIGENDIAN(define = "AV_HAVE_BIGENDIAN"),
    checks.AC_TRY_COMPILE(
        define = "AV_HAVE_FAST_UNALIGNED",
        code = (
            "#if !(defined(__aarch64__) || defined(__arm__)" +
            " || defined(__powerpc__) || defined(__powerpc64__)" +
            " || defined(__i386__) || defined(__x86_64__))\n" +
            "#error\n#endif"
        ),
    ),
]
