Skip to content

ALLOCATOR_OF

Description

Convert any allocator pointer to Allocator *. The argument may be:

  • a typed allocator pointer (HeapAllocator *, PageAllocator *,

ArenaAllocator *, SlabAllocator *, BudgetAllocator *, DebugAllocator *), in which case the macro typecasts the whole pointer to Allocator *. The cast is safe because every typed allocator carries Allocator base at offset zero — the C-style inheritance contract.

  • a raw Allocator *, which is returned unchanged.

Any other pointer type triggers a _Generic mismatch at compile time, which is the type-safety check the macro layer provides.

Callers do not write &heap.base or (Allocator *)&heap by hand — every macro that takes an allocator pointer routes it through this macro first.

Usage example (from documentation)


    HeapAllocator heap = HeapAllocatorInit();
    Vec(int) v = VecInit(&heap);   // macro internally does ALLOCATOR_OF(&heap)

    void library_helper(Vec *v, Allocator *alloc) {
        Vec(int) scratch = VecInit(alloc);   // raw Allocator* also accepted
    }

Adding a new typed allocator requires adding it to this whitelist
(and forward-declaring it above).

Note for new code: the conventions doc (CODING-CONVENTIONS.md,
"_Generic dispatch") asks each macro to inline its own _Generic
instead of going through a shared "convert type X to Y" helper.
`ALLOCATOR_OF` is the project-wide exception: it's the single
canonical erasure point used by every container init macro and
every parser/sys backend that needs to take an `Allocator *`
from a typed-allocator handle. Folding it inline at every
call site would explode the dispatch surface; keeping the
shared name makes the type-erasure step searchable.

Success

Expands to an Allocator * referring to the same instance.

Failure

Compile-time _Generic mismatch on any pointer type that is not Allocator * or one of the listed typed allocator pointers.

Usage example (Cross-references)

Usage examples (Cross-references)
    #define ZstrDupN(...)             OVERLOAD(ZstrDupN, __VA_ARGS__)
    #define ZstrDupN_2(src, n)        zstr_dup_n((src), (n), MisraScope)
    #define ZstrDupN_3(src, n, alloc) zstr_dup_n((src), (n), ALLOCATOR_OF(alloc))
    
    ///
    #define ZstrDup(...)          OVERLOAD(ZstrDup, __VA_ARGS__)
    #define ZstrDup_1(src)        zstr_dup((src), MisraScope)
    #define ZstrDup_2(src, alloc) zstr_dup((src), ALLOCATOR_OF(alloc))
    
    ///
        ((                                                                                                                 \
            ArgParse                                                                                                       \
        ) {.alloc = ALLOCATOR_OF(alloc_ptr), .name = (prog_name), .about = (prog_about), .specs = VecInit_1(alloc_ptr)})
    
        ///
    #define FileOpenTemp(...)               OVERLOAD(FileOpenTemp, __VA_ARGS__)
    #define FileOpenTemp_1(out_path)        file_open_temp((out_path), MisraScope)
    #define FileOpenTemp_2(out_path, alloc) file_open_temp((out_path), ALLOCATOR_OF(alloc))
    
    #endif // MISRA_STD_FILE_H
        /// TAGS: Allocator, Stats, Accessor
        ///
    #    define AllocatorBytesRequested(a)    ((void)0, ALLOCATOR_OF(a)->stats.bytes_requested)
    #    define AllocatorBytesInUse(a)        ((void)0, ALLOCATOR_OF(a)->stats.bytes_in_use)
    #    define AllocatorPeakBytesInUse(a)    ((void)0, ALLOCATOR_OF(a)->stats.peak_bytes_in_use)
        ///
    #    define AllocatorBytesRequested(a)    ((void)0, ALLOCATOR_OF(a)->stats.bytes_requested)
    #    define AllocatorBytesInUse(a)        ((void)0, ALLOCATOR_OF(a)->stats.bytes_in_use)
    #    define AllocatorPeakBytesInUse(a)    ((void)0, ALLOCATOR_OF(a)->stats.peak_bytes_in_use)
    #    define AllocatorAllocations(a)       ((void)0, ALLOCATOR_OF(a)->stats.allocations)
    #    define AllocatorBytesRequested(a)    ((void)0, ALLOCATOR_OF(a)->stats.bytes_requested)
    #    define AllocatorBytesInUse(a)        ((void)0, ALLOCATOR_OF(a)->stats.bytes_in_use)
    #    define AllocatorPeakBytesInUse(a)    ((void)0, ALLOCATOR_OF(a)->stats.peak_bytes_in_use)
    #    define AllocatorAllocations(a)       ((void)0, ALLOCATOR_OF(a)->stats.allocations)
    #    define AllocatorReallocations(a)     ((void)0, ALLOCATOR_OF(a)->stats.reallocations)
    #    define AllocatorBytesInUse(a)        ((void)0, ALLOCATOR_OF(a)->stats.bytes_in_use)
    #    define AllocatorPeakBytesInUse(a)    ((void)0, ALLOCATOR_OF(a)->stats.peak_bytes_in_use)
    #    define AllocatorAllocations(a)       ((void)0, ALLOCATOR_OF(a)->stats.allocations)
    #    define AllocatorReallocations(a)     ((void)0, ALLOCATOR_OF(a)->stats.reallocations)
    #    define AllocatorDeallocations(a)     ((void)0, ALLOCATOR_OF(a)->stats.deallocations)
    #    define AllocatorPeakBytesInUse(a)    ((void)0, ALLOCATOR_OF(a)->stats.peak_bytes_in_use)
    #    define AllocatorAllocations(a)       ((void)0, ALLOCATOR_OF(a)->stats.allocations)
    #    define AllocatorReallocations(a)     ((void)0, ALLOCATOR_OF(a)->stats.reallocations)
    #    define AllocatorDeallocations(a)     ((void)0, ALLOCATOR_OF(a)->stats.deallocations)
    #    define AllocatorFailedAllocations(a) ((void)0, ALLOCATOR_OF(a)->stats.failed_allocations)
    #    define AllocatorAllocations(a)       ((void)0, ALLOCATOR_OF(a)->stats.allocations)
    #    define AllocatorReallocations(a)     ((void)0, ALLOCATOR_OF(a)->stats.reallocations)
    #    define AllocatorDeallocations(a)     ((void)0, ALLOCATOR_OF(a)->stats.deallocations)
    #    define AllocatorFailedAllocations(a) ((void)0, ALLOCATOR_OF(a)->stats.failed_allocations)
    #    define AllocatorReallocations(a)     ((void)0, ALLOCATOR_OF(a)->stats.reallocations)
    #    define AllocatorDeallocations(a)     ((void)0, ALLOCATOR_OF(a)->stats.deallocations)
    #    define AllocatorFailedAllocations(a) ((void)0, ALLOCATOR_OF(a)->stats.failed_allocations)
    
        ///
    /// TAGS: Allocator, Memory, Observability
    ///
    #define AllocatorFootprintBytes(a) ((void)0, ALLOCATOR_OF(a)->footprint_bytes)
    
    ///
    /// TAGS: Allocator, Alignment, Accessor
    ///
    #define AllocatorAlignment(a) ((void)0, ALLOCATOR_OF(a)->alignment)
    
    // Typed allocator headers (PageAllocator, HeapAllocator, ArenaAllocator,
            float_try_to_decimal_str((out), (value), (precision), (has_precision), MisraScope)
    #    define FloatTryToDecimalStr_5(out, value, precision, has_precision, alloc)                                        \
            float_try_to_decimal_str((out), (value), (precision), (has_precision), ALLOCATOR_OF(alloc))
    
    ///
            float_try_to_scientific_str((out), (value), (precision), (has_precision), (uppercase), MisraScope)
    #    define FloatTryToScientificStr_6(out, value, precision, has_precision, uppercase, alloc)                          \
            float_try_to_scientific_str((out), (value), (precision), (has_precision), (uppercase), ALLOCATOR_OF(alloc))
    #endif // FEATURE_FLOAT
         .pending_delete_count  = 0,                                                                                       \
         .mutation_epoch        = 0,                                                                                       \
         .allocator             = ALLOCATOR_OF(typed_alloc_ptr),                                                           \
         .__magic               = GRAPH_MAGIC | MAGIC_VALIDATED_BIT}
            _Generic((value), Int *: float_from_int, unsigned char: float_from_u64, unsigned short: float_from_u64, unsigned int: float_from_u64, unsigned long: float_from_u64, unsigned long long: float_from_u64, signed char: float_from_i64, signed short: float_from_i64, signed int: float_from_i64, signed long: float_from_i64, signed long long: float_from_i64, float: float_from_f32, double: float_from_f64)( \
                (value),                                                                                                                                                                                                                                                                                                                                                                                                   \
                ALLOCATOR_OF(allocator_ptr)                                                                                                                                                                                                                                                                                                                                                                                \
            )
    #endif
        _Generic((text), Str *: float_from_str_str, Zstr: float_from_str_zstr, char *: float_from_str_zstr)(               \
            (text),                                                                                                        \
            ALLOCATOR_OF(alloc)                                                                                            \
        )
         .copy_deinit = NULL,                                                                                              \
         .data        = NULL,                                                                                              \
         .allocator   = ALLOCATOR_OF(allocator_ptr),                                                                       \
         .__magic     = VEC_MAGIC | MAGIC_VALIDATED_BIT}
         .copy_deinit = (GenericCopyDeinit)(cd),                                                                           \
         .data        = NULL,                                                                                              \
         .allocator   = ALLOCATOR_OF(allocator_ptr),                                                                       \
         .__magic     = VEC_MAGIC | MAGIC_VALIDATED_BIT}
            (out),                                                                                                         \
            (str),                                                                                                         \
            ALLOCATOR_OF(alloc)                                                                                            \
        )
        _Generic((str), Str *: bitvec_from_str_str, Zstr: bitvec_from_str_zstr, char *: bitvec_from_str_zstr)(             \
            (str),                                                                                                         \
            ALLOCATOR_OF(alloc)                                                                                            \
        )
    #define BitVecTryFromBytes_3(out, bytes, bit_len) bitvec_try_from_bytes((out), (bytes), (bit_len), MisraScope)
    #define BitVecTryFromBytes_4(out, bytes, bit_len, alloc)                                                               \
        bitvec_try_from_bytes((out), (bytes), (bit_len), ALLOCATOR_OF(alloc))
    
        ///
    #define BitVecFromBytes(...)                     OVERLOAD(BitVecFromBytes, __VA_ARGS__)
    #define BitVecFromBytes_2(bytes, bit_len)        bitvec_from_bytes((bytes), (bit_len), MisraScope)
    #define BitVecFromBytes_3(bytes, bit_len, alloc) bitvec_from_bytes((bytes), (bit_len), ALLOCATOR_OF(alloc))
    
        ///
    #define BitVecTryFromInteger_3(out, value, bits) bitvec_try_from_integer((out), (value), (bits), MisraScope)
    #define BitVecTryFromInteger_4(out, value, bits, alloc)                                                                \
        bitvec_try_from_integer((out), (value), (bits), ALLOCATOR_OF(alloc))
    
        ///
    #define BitVecFromInteger(...)                  OVERLOAD(BitVecFromInteger, __VA_ARGS__)
    #define BitVecFromInteger_2(value, bits)        bitvec_from_integer((value), (bits), MisraScope)
    #define BitVecFromInteger_3(value, bits, alloc) bitvec_from_integer((value), (bits), ALLOCATOR_OF(alloc))
    
    #ifdef __cplusplus
                .data      = NULL,                                                                                         \
                .byte_size = 0,                                                                                            \
                .allocator = ALLOCATOR_OF(allocator_ptr),                                                                  \
                .__magic   = BITVEC_MAGIC | MAGIC_VALIDATED_BIT                                                            \
            })
                       .data      = NULL,                                                                                  \
                       .byte_size = 0,                                                                                     \
                       .allocator = ALLOCATOR_OF(allocator_ptr),                                                           \
                       .__magic   = BITVEC_MAGIC | MAGIC_VALIDATED_BIT})
    #endif
            _Generic((value), unsigned char: int_from_u64, unsigned short: int_from_u64, unsigned int: int_from_u64, unsigned long: int_from_u64, unsigned long long: int_from_u64, signed char: int_from_i64, signed short: int_from_i64, signed int: int_from_i64, signed long: int_from_i64, signed long long: int_from_i64)( \
                (value),                                                                                                                                                                                                                                                                                                         \
                ALLOCATOR_OF(alloc)                                                                                                                                                                                                                                                                                              \
            )
    #endif
    #define IntFromBytesLE(...)                 OVERLOAD(IntFromBytesLE, __VA_ARGS__)
    #define IntFromBytesLE_2(bytes, len)        int_from_bytes_le((bytes), (len), MisraScope)
    #define IntFromBytesLE_3(bytes, len, alloc) int_from_bytes_le((bytes), (len), ALLOCATOR_OF(alloc))
    
        ///
    #define IntFromBytesBE(...)                 OVERLOAD(IntFromBytesBE, __VA_ARGS__)
    #define IntFromBytesBE_2(bytes, len)        int_from_bytes_be((bytes), (len), MisraScope)
    #define IntFromBytesBE_3(bytes, len, alloc) int_from_bytes_be((bytes), (len), ALLOCATOR_OF(alloc))
    
        ///
            (digits),                                                                                                      \
            (radix),                                                                                                       \
            ALLOCATOR_OF(alloc)                                                                                            \
        )
        _Generic((decimal), Str *: int_from_str_str, Zstr: int_from_str_zstr, char *: int_from_str_zstr)(                  \
            (decimal),                                                                                                     \
            ALLOCATOR_OF(alloc)                                                                                            \
        )
        _Generic((binary), Str *: int_from_binary_str, Zstr: int_from_binary_zstr, char *: int_from_binary_zstr)(          \
            (binary),                                                                                                      \
            ALLOCATOR_OF(alloc)                                                                                            \
        )
        _Generic((octal), Str *: int_from_oct_str_str, Zstr: int_from_oct_str_zstr, char *: int_from_oct_str_zstr)(        \
            (octal),                                                                                                       \
            ALLOCATOR_OF(alloc)                                                                                            \
        )
        _Generic((hex), Str *: int_from_hex_str_str, Zstr: int_from_hex_str_zstr, char *: int_from_hex_str_zstr)(          \
            (hex),                                                                                                         \
            ALLOCATOR_OF(alloc)                                                                                            \
        )
    ///
    #define StrTryInitFromCstr(out, cstr, len, allocator_ptr)                                                              \
        str_try_init_from_cstr((out), (cstr), (len), ALLOCATOR_OF(allocator_ptr))
    
    ///
    #define StrInitFromCstr(...)                OVERLOAD(StrInitFromCstr, __VA_ARGS__)
    #define StrInitFromCstr_2(cstr, len)        str_init_from_cstr((cstr), (len), MisraScope)
    #define StrInitFromCstr_3(cstr, len, alloc) str_init_from_cstr((cstr), (len), ALLOCATOR_OF(alloc))
    
    ///
         .copy_deinit = (GenericCopyDeinit)(cd),                                                                           \
         .length      = 0,                                                                                                 \
         .allocator   = ALLOCATOR_OF(typed_alloc_ptr),                                                                     \
         .__magic     = LIST_MAGIC | MAGIC_VALIDATED_BIT}
         .states            = NULL,                                                                                        \
         .policy            = validate_map_policy_copy((policy_value)),                                                    \
         .allocator         = ALLOCATOR_OF(typed_alloc_ptr),                                                               \
         .__magic           = MAP_MAGIC | MAGIC_VALIDATED_BIT}
    #define SocketAddrFormat(...)           OVERLOAD(SocketAddrFormat, __VA_ARGS__)
    #define SocketAddrFormat_1(addr)        socket_addr_format((addr), MisraScope)
    #define SocketAddrFormat_2(addr, alloc) socket_addr_format((addr), ALLOCATOR_OF(alloc))
    
    // --- Listener (server side) -------------------------------------------------
        _Generic(                                                                                                          \
            (path),                                                                                                        \
            Str *: dir_get_contents((Zstr)StrBegin((Str *)(path)), ALLOCATOR_OF(alloc)),                                   \
            Zstr: dir_get_contents((Zstr)(path), ALLOCATOR_OF(alloc)),                                                     \
            char *: dir_get_contents((Zstr)(path), ALLOCATOR_OF(alloc))                                                    \
            (path),                                                                                                        \
            Str *: dir_get_contents((Zstr)StrBegin((Str *)(path)), ALLOCATOR_OF(alloc)),                                   \
            Zstr: dir_get_contents((Zstr)(path), ALLOCATOR_OF(alloc)),                                                     \
            char *: dir_get_contents((Zstr)(path), ALLOCATOR_OF(alloc))                                                    \
        )
            Str *: dir_get_contents((Zstr)StrBegin((Str *)(path)), ALLOCATOR_OF(alloc)),                                   \
            Zstr: dir_get_contents((Zstr)(path), ALLOCATOR_OF(alloc)),                                                     \
            char *: dir_get_contents((Zstr)(path), ALLOCATOR_OF(alloc))                                                    \
        )
    #define PdbCacheInit(...)         OVERLOAD(PdbCacheInit, __VA_ARGS__)
    #define PdbCacheInit_0()          PdbCacheInit_1(MisraScope)
    #define PdbCacheInit_1(alloc_ptr) ((PdbCache) {.allocator = ALLOCATOR_OF(alloc_ptr), .entries = VecInit_1(alloc_ptr)})
    
    ///
    #define ProcInit(...)                       OVERLOAD(ProcInit, __VA_ARGS__)
    #define ProcInit_3(path, argv, envp)        proc_init((path), (argv), (envp), MisraScope)
    #define ProcInit_4(path, argv, envp, alloc) proc_init((path), (argv), (envp), ALLOCATOR_OF(alloc))
    
        ///
    #define SymbolResolverInit(...)          OVERLOAD(SymbolResolverInit, __VA_ARGS__)
    #define SymbolResolverInit_1(out)        symbol_resolver_init((out), MisraScope)
    #define SymbolResolverInit_2(out, alloc) symbol_resolver_init((out), ALLOCATOR_OF(alloc))
    
    ///
    #define DnsResolverInit(...)          OVERLOAD(DnsResolverInit, __VA_ARGS__)
    #define DnsResolverInit_1(out)        dns_resolver_init((out), MisraScope)
    #define DnsResolverInit_2(out, alloc) dns_resolver_init((out), ALLOCATOR_OF(alloc))
    
        ///
    #define MachoCacheInit(...)         OVERLOAD(MachoCacheInit, __VA_ARGS__)
    #define MachoCacheInit_0()          MachoCacheInit_1(MisraScope)
    #define MachoCacheInit_1(alloc_ptr) ((MachoCache) {.allocator = ALLOCATOR_OF(alloc_ptr), .entries = VecInit_1(alloc_ptr)})
    
    ///
    #define HttpRequestInit_0()  HttpRequestInit_1(MisraScope)
    #define HttpRequestInit_1(alloc_ptr)                                                                                   \
        ((HttpRequest) {.allocator = ALLOCATOR_OF(alloc_ptr),                                                              \
                        .method    = HTTP_REQUEST_METHOD_UNKNOWN,                                                          \
                        .url       = StrInit_1(alloc_ptr),                                                                 \
    #define HttpResponseInit_0()  HttpResponseInit_1(MisraScope)
    #define HttpResponseInit_1(alloc_ptr)                                                                                  \
        ((HttpResponse) {.allocator    = ALLOCATOR_OF(alloc_ptr),                                                          \
                         .content_type = HTTP_CONTENT_TYPE_INVALID,                                                        \
                         .status_code  = HTTP_RESPONSE_CODE_INVALID,                                                       \
    #define HttpResponseSerialize(...)               OVERLOAD(HttpResponseSerialize, __VA_ARGS__)
    #define HttpResponseSerialize_1(response)        http_response_serialize((response), MisraScope)
    #define HttpResponseSerialize_2(response, alloc) http_response_serialize((response), ALLOCATOR_OF(alloc))
    
    ///
        _Generic(                                                                                                          \
            (path),                                                                                                        \
            Str *: pdb_open((out), (Zstr)StrBegin((Str *)(path)), ALLOCATOR_OF(alloc)),                                    \
            Zstr: pdb_open((out), (Zstr)(path), ALLOCATOR_OF(alloc)),                                                      \
            char *: pdb_open((out), (Zstr)(path), ALLOCATOR_OF(alloc))                                                     \
            (path),                                                                                                        \
            Str *: pdb_open((out), (Zstr)StrBegin((Str *)(path)), ALLOCATOR_OF(alloc)),                                    \
            Zstr: pdb_open((out), (Zstr)(path), ALLOCATOR_OF(alloc)),                                                      \
            char *: pdb_open((out), (Zstr)(path), ALLOCATOR_OF(alloc))                                                     \
        )
            Str *: pdb_open((out), (Zstr)StrBegin((Str *)(path)), ALLOCATOR_OF(alloc)),                                    \
            Zstr: pdb_open((out), (Zstr)(path), ALLOCATOR_OF(alloc)),                                                      \
            char *: pdb_open((out), (Zstr)(path), ALLOCATOR_OF(alloc))                                                     \
        )
    #define PdbOpenFromMemoryCopy_3(out, data, data_size) pdb_open_from_memory_copy((out), (data), (data_size), MisraScope)
    #define PdbOpenFromMemoryCopy_4(out, data, data_size, alloc)                                                           \
        pdb_open_from_memory_copy((out), (data), (data_size), ALLOCATOR_OF(alloc))
    
    ///
    #define DwarfLinesBuildFromElf(...)               OVERLOAD(DwarfLinesBuildFromElf, __VA_ARGS__)
    #define DwarfLinesBuildFromElf_2(out, elf)        dwarf_lines_build_from_elf((out), (elf), MisraScope)
    #define DwarfLinesBuildFromElf_3(out, elf, alloc) dwarf_lines_build_from_elf((out), (elf), ALLOCATOR_OF(alloc))
    
    ///
    #define DwarfCfiBuildFromElf(...)               OVERLOAD(DwarfCfiBuildFromElf, __VA_ARGS__)
    #define DwarfCfiBuildFromElf_2(out, elf)        dwarf_cfi_build_from_elf((out), (elf), MisraScope)
    #define DwarfCfiBuildFromElf_3(out, elf, alloc) dwarf_cfi_build_from_elf((out), (elf), ALLOCATOR_OF(alloc))
    
    ///
    #define DwarfFunctionsBuildFromElf(...)               OVERLOAD(DwarfFunctionsBuildFromElf, __VA_ARGS__)
    #define DwarfFunctionsBuildFromElf_2(out, elf)        dwarf_functions_build_from_elf((out), (elf), MisraScope)
    #define DwarfFunctionsBuildFromElf_3(out, elf, alloc) dwarf_functions_build_from_elf((out), (elf), ALLOCATOR_OF(alloc))
    
    ///
        _Generic(                                                                                                          \
            (path),                                                                                                        \
            Str *: elf_open((out), (Zstr)StrBegin((Str *)(path)), ALLOCATOR_OF(alloc)),                                    \
            Zstr: elf_open((out), (Zstr)(path), ALLOCATOR_OF(alloc)),                                                      \
            char *: elf_open((out), (Zstr)(path), ALLOCATOR_OF(alloc))                                                     \
            (path),                                                                                                        \
            Str *: elf_open((out), (Zstr)StrBegin((Str *)(path)), ALLOCATOR_OF(alloc)),                                    \
            Zstr: elf_open((out), (Zstr)(path), ALLOCATOR_OF(alloc)),                                                      \
            char *: elf_open((out), (Zstr)(path), ALLOCATOR_OF(alloc))                                                     \
        )
            Str *: elf_open((out), (Zstr)StrBegin((Str *)(path)), ALLOCATOR_OF(alloc)),                                    \
            Zstr: elf_open((out), (Zstr)(path), ALLOCATOR_OF(alloc)),                                                      \
            char *: elf_open((out), (Zstr)(path), ALLOCATOR_OF(alloc))                                                     \
        )
    #define ElfOpenFromMemoryCopy_3(out, data, data_size) elf_open_from_memory_copy((out), (data), (data_size), MisraScope)
    #define ElfOpenFromMemoryCopy_4(out, data, data_size, alloc)                                                           \
        elf_open_from_memory_copy((out), (data), (data_size), ALLOCATOR_OF(alloc))
    
    ///
        _Generic(                                                                                                          \
            (path),                                                                                                        \
            Str *: pe_open((out), (Zstr)StrBegin((Str *)(path)), ALLOCATOR_OF(alloc)),                                     \
            Zstr: pe_open((out), (Zstr)(path), ALLOCATOR_OF(alloc)),                                                       \
            char *: pe_open((out), (Zstr)(path), ALLOCATOR_OF(alloc))                                                      \
            (path),                                                                                                        \
            Str *: pe_open((out), (Zstr)StrBegin((Str *)(path)), ALLOCATOR_OF(alloc)),                                     \
            Zstr: pe_open((out), (Zstr)(path), ALLOCATOR_OF(alloc)),                                                       \
            char *: pe_open((out), (Zstr)(path), ALLOCATOR_OF(alloc))                                                      \
        )
            Str *: pe_open((out), (Zstr)StrBegin((Str *)(path)), ALLOCATOR_OF(alloc)),                                     \
            Zstr: pe_open((out), (Zstr)(path), ALLOCATOR_OF(alloc)),                                                       \
            char *: pe_open((out), (Zstr)(path), ALLOCATOR_OF(alloc))                                                      \
        )
    #define PeOpenFromMemoryCopy_3(out, data, data_size) pe_open_from_memory_copy((out), (data), (data_size), MisraScope)
    #define PeOpenFromMemoryCopy_4(out, data, data_size, alloc)                                                            \
        pe_open_from_memory_copy((out), (data), (data_size), ALLOCATOR_OF(alloc))
    
    ///
        _Generic(                                                                                                          \
            (path),                                                                                                        \
            Str *: macho_open((out), (Zstr)StrBegin((Str *)(path)), ALLOCATOR_OF(alloc)),                                  \
            Zstr: macho_open((out), (Zstr)(path), ALLOCATOR_OF(alloc)),                                                    \
            char *: macho_open((out), (Zstr)(path), ALLOCATOR_OF(alloc))                                                   \
            (path),                                                                                                        \
            Str *: macho_open((out), (Zstr)StrBegin((Str *)(path)), ALLOCATOR_OF(alloc)),                                  \
            Zstr: macho_open((out), (Zstr)(path), ALLOCATOR_OF(alloc)),                                                    \
            char *: macho_open((out), (Zstr)(path), ALLOCATOR_OF(alloc))                                                   \
        )
            Str *: macho_open((out), (Zstr)StrBegin((Str *)(path)), ALLOCATOR_OF(alloc)),                                  \
            Zstr: macho_open((out), (Zstr)(path), ALLOCATOR_OF(alloc)),                                                    \
            char *: macho_open((out), (Zstr)(path), ALLOCATOR_OF(alloc))                                                   \
        )
        macho_open_from_memory_copy((out), (data), (data_size), MisraScope)
    #define MachoOpenFromMemoryCopy_4(out, data, data_size, alloc)                                                         \
        macho_open_from_memory_copy((out), (data), (data_size), ALLOCATOR_OF(alloc))
    
    ///
    #define ProcMapsLoad(...)          OVERLOAD(ProcMapsLoad, __VA_ARGS__)
    #define ProcMapsLoad_1(out)        proc_maps_load((out), MisraScope)
    #define ProcMapsLoad_2(out, alloc) proc_maps_load((out), ALLOCATOR_OF(alloc))
    
    ///
        _Generic(                                                                                                          \
            (src),                                                                                                         \
            File *: proc_maps_load_from_file((out), (File *)(src), ALLOCATOR_OF(alloc)),                                   \
            Str *: proc_maps_load_from_bytes(                                                                              \
                     (out),                                                                                                \
                     (const u8 *)StrBegin((Str *)(src)),                                                                   \
                     StrLen((Str *)(src)),                                                                                 \
                     ALLOCATOR_OF(alloc)                                                                                   \
                 ),                                                                                                        \
            Buf *: proc_maps_load_from_bytes((out), BufData((Buf *)(src)), BufLength((Buf *)(src)), ALLOCATOR_OF(alloc))   \
                     ALLOCATOR_OF(alloc)                                                                                   \
                 ),                                                                                                        \
            Buf *: proc_maps_load_from_bytes((out), BufData((Buf *)(src)), BufLength((Buf *)(src)), ALLOCATOR_OF(alloc))   \
        )
    #define ProcMapsLoadFrom_4(out, bytes, len, alloc)                                                                     \
        )
    #define ProcMapsLoadFrom_4(out, bytes, len, alloc)                                                                     \
        proc_maps_load_from_bytes((out), (const u8 *)(bytes), (len), ALLOCATOR_OF(alloc))
    
    ///
            // FormatStackTrace takes `Allocator *` -- legitimate erasure
            // boundary; pass at the call site, no intermediate variable.
            FormatStackTrace(&trace, frames, n, ALLOCATOR_OF(&h));
            (void)FileWrite(&out, StrBegin(&trace), StrLen(&trace));
            StrDeinit(&trace);
        // intentional bypass: Debug allocator swap; no public MapSetAllocator mutator.
        if (!self->live.allocator) {
            ((DebugAllocator *)(void *)self)->live.allocator = ALLOCATOR_OF(&((DebugAllocator *)(void *)self)->meta);
        }
        if (!self->freed.allocator) {
        }
        if (!self->freed.allocator) {
            ((DebugAllocator *)(void *)self)->freed.allocator = ALLOCATOR_OF(&((DebugAllocator *)(void *)self)->meta);
        }
        if (!(self->base.__magic & MAGIC_VALIDATED_BIT)) {
                    (u64)fe->requested_size
                );
                debug_emit_trace(fe->alloc_trace, fe->alloc_trace_n, "alloc", ALLOCATOR_OF(&self->meta));
                debug_emit_trace(fe->free_trace, fe->free_trace_n, "first-free", ALLOCATOR_OF(&self->meta));
                LOG_FATAL("DebugAllocator: double-free of {x}", (u64)ptr);
                );
                debug_emit_trace(fe->alloc_trace, fe->alloc_trace_n, "alloc", ALLOCATOR_OF(&self->meta));
                debug_emit_trace(fe->free_trace, fe->free_trace_n, "first-free", ALLOCATOR_OF(&self->meta));
                LOG_FATAL("DebugAllocator: double-free of {x}", (u64)ptr);
                return 0;
                    (u64)live_rec->requested_size
                );
                debug_emit_trace(live_rec->alloc_trace, live_rec->alloc_trace_n, "alloc", ALLOCATOR_OF(&self->meta));
            }
        }
            MapForeachPairPtr(&self->live, key_ptr, val_ptr) {
                LOG_ERROR("  leaked {x} ({} bytes)", (u64)*key_ptr, (u64)val_ptr->requested_size);
                debug_emit_trace(val_ptr->alloc_trace, val_ptr->alloc_trace_n, "alloc", ALLOCATOR_OF(&self->meta));
            }
        }
            if (val_ptr->alloc_trace_n > 0) {
    #if !defined(LOG_NO_BACKTRACE) || !LOG_NO_BACKTRACE
                FormatStackTrace(out, val_ptr->alloc_trace, val_ptr->alloc_trace_n, ALLOCATOR_OF(&self->meta));
    #else
                for (size i = 0; i < val_ptr->alloc_trace_n; ++i) {
        // by both typed and erased callers) -- legitimate erasure boundary;
        // pass at the call site, no intermediate variable.
        DirContents dc = dir_get_contents(path, ALLOCATOR_OF(&ha));
    
        bool ok        = true;
        // DnsParseResponse takes `Allocator *` -- legitimate erasure
        // boundary; pass at the call site, no intermediate variable.
        bool ok = DnsParseResponse(&resp, resp_buf, (u64)got, ALLOCATOR_OF(&scratch));
        if (!ok || resp.id != id || resp.rcode != DNS_RCODE_NOERROR) {
            DnsResponseDeinit(&resp);
        DefaultAllocator alloc  = DefaultAllocatorInit();
        i32              offset = 0;
        bool             ok     = TzifLocalOffsetSeconds((i64)(ns / 1000000000ull), &offset, ALLOCATOR_OF(&alloc));
        DefaultAllocatorDeinit(&alloc);
        if (ok)
    bool test_page_protect_roundtrip(void) {
        PageAllocator page = PageAllocatorInit();
        Allocator    *base = ALLOCATOR_OF(&page);
    
        size  page_bytes = PageAllocatorPageSize(&page);
    
        DefaultAllocator alloc      = DefaultAllocatorInit();
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        Str path;
    
        DefaultAllocator alloc      = DefaultAllocatorInit();
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        Str path;
    
        DefaultAllocator alloc      = DefaultAllocatorInit();
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        Str  path;
    
        DefaultAllocator alloc      = DefaultAllocatorInit();
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        Str  path;
    
        DefaultAllocator alloc      = DefaultAllocatorInit();
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        Str  path;
    
        DefaultAllocator alloc      = DefaultAllocatorInit();
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        Str  path;
    
        DefaultAllocator alloc      = DefaultAllocatorInit();
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        Str  path;
    
        DefaultAllocator alloc      = DefaultAllocatorInit();
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        Str  path;
    
        DefaultAllocator alloc      = DefaultAllocatorInit();
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        // Need a path on disk; create+remove a temp to mint a unique name,
    
        DefaultAllocator alloc      = DefaultAllocatorInit();
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        // Mint a unique name then remove it so the path is guaranteed absent.
    
        DefaultAllocator alloc      = DefaultAllocatorInit();
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        Str  path;
    
        DefaultAllocator alloc      = DefaultAllocatorInit();
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        Str  path;
    
        DefaultAllocator alloc      = DefaultAllocatorInit();
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        Str  path;
    
        DefaultAllocator alloc      = DefaultAllocatorInit();
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        Str  path;
    
        DefaultAllocator alloc      = DefaultAllocatorInit();
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        Str  path;
    
        DefaultAllocator alloc      = DefaultAllocatorInit();
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        Str  path;
    
        DefaultAllocator alloc      = DefaultAllocatorInit();
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        Str  path;
    
        DefaultAllocator alloc      = DefaultAllocatorInit();
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        Str  path;
    
        DefaultAllocator alloc      = DefaultAllocatorInit();
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        Str  path;
    
        DefaultAllocator alloc      = DefaultAllocatorInit();
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        Str  path;
    
        DefaultAllocator alloc      = DefaultAllocatorInit();
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        Str  path;
    
        DefaultAllocator alloc      = DefaultAllocatorInit();
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        Str  path;
    
        DefaultAllocator alloc      = DefaultAllocatorInit();
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        // Build a 10000-byte payload (> FILE_READ_CHUNK=4096) on disk.
    
        DefaultAllocator alloc      = DefaultAllocatorInit();
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        Str  path;
    
        DefaultAllocator alloc      = DefaultAllocatorInit();
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        Str  path;
    
        DefaultAllocator alloc      = DefaultAllocatorInit();
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        Str  path;
    
        DefaultAllocator alloc      = DefaultAllocatorInit();
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        Str  path;
    
        DefaultAllocator alloc      = DefaultAllocatorInit();
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        Str  path;
    
        DefaultAllocator alloc      = DefaultAllocatorInit();
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        Str  p1;
    
        DefaultAllocator alloc      = DefaultAllocatorInit();
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        Str  path;
    
        DefaultAllocator alloc      = DefaultAllocatorInit();
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        Str  path;
    
        DefaultAllocator alloc      = DefaultAllocatorInit();
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        // Seed a temp path that exists on disk (so the open succeeds).
    
        DefaultAllocator alloc      = DefaultAllocatorInit();
        Allocator       *alloc_base = ALLOCATOR_OF(&alloc);
    
        // Open file A and keep a second file B open so A's fd slot sits in the
    bool test_debug_normal_alloc_free(void) {
        DebugAllocator dbg  = DebugAllocatorInit();
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
        void *p1 = AllocatorAlloc(adbg, 64, true);
    bool test_debug_zero_byte_alloc(void) {
        DebugAllocator dbg  = DebugAllocatorInit();
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
        void *p  = AllocatorAlloc(adbg, 0, false);
    bool test_debug_null_free_is_noop(void) {
        DebugAllocator dbg  = DebugAllocatorInit();
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
        AllocatorFree(adbg, NULL); // no-op, must not crash
    bool test_debug_catches_overflow(void) {
        DebugAllocator dbg  = DebugAllocatorInit();
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
        u8 *buf = (u8 *)AllocatorAlloc(adbg, 16, true);
    bool test_debug_leak_count(void) {
        DebugAllocator dbg  = DebugAllocatorInit();
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
        (void)AllocatorAlloc(adbg, 32, true);
    bool test_debug_report_leaks_emits_traces(void) {
        DebugAllocator dbg  = DebugAllocatorInit();
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
        void *p1 = AllocatorAlloc(adbg, 24, true);
    bool test_debug_alloc_trace_captured(void) {
        DebugAllocator dbg  = DebugAllocatorInit();
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
        void *p  = AllocatorAlloc(adbg, 64, false);
    bool test_debug_freed_history_grows_on_free(void) {
        DebugAllocator dbg  = DebugAllocatorInit();
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
        bool  ok = (DebugAllocatorFreedCount(&dbg) == 0);
        cfg.track_freed_history  = false;
        DebugAllocator dbg       = DebugAllocatorInitWith(cfg);
        Allocator     *adbg      = ALLOCATOR_OF(&dbg);
    
        bool ok = true;
    bool test_debug_remap_grows(void) {
        DebugAllocator dbg  = DebugAllocatorInit();
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
        u8  *p  = (u8 *)AllocatorAlloc(adbg, 16, true);
    bool test_debug_remap_to_zero_frees(void) {
        DebugAllocator dbg  = DebugAllocatorInit();
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
        void *p   = AllocatorAlloc(adbg, 24, false);
    bool test_debug_remap_from_null_allocates(void) {
        DebugAllocator dbg  = DebugAllocatorInit();
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
        void *p  = AllocatorRealloc(adbg, NULL, 32);
        cfg.force_page_backing   = true;
        DebugAllocator dbg       = DebugAllocatorInitWith(cfg);
        Allocator     *adbg      = ALLOCATOR_OF(&dbg);
    
        void *p  = AllocatorAlloc(adbg, 64, true);
    bool test_debug_double_free_aborts(void) {
        DebugAllocator dbg  = DebugAllocatorInit();
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
        void *p = AllocatorAlloc(adbg, 32, true);
        // foreign pointer.
        DebugAllocator dbg  = DebugAllocatorInit();
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
        u8 junk[64];
    bool test_ad1_canary_detects_non_first_byte(void) {
        DebugAllocator dbg  = DebugAllocatorInit();
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
        u8  *buf = (u8 *)AllocatorAlloc(adbg, 16, true);
    bool test_ad1_freed_alloc_trace_n_copied(void) {
        DebugAllocator dbg  = DebugAllocatorInit();
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
        void *p  = AllocatorAlloc(adbg, 48, false);
    bool test_ad1_freed_alloc_trace_bytes_copied(void) {
        DebugAllocator dbg  = DebugAllocatorInit();
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
        void *p  = AllocatorAlloc(adbg, 48, false);
        cfg.capture_traces       = false;
        DebugAllocator dbg       = DebugAllocatorInitWith(cfg);
        Allocator     *adbg      = ALLOCATOR_OF(&dbg);
    
        void *p  = AllocatorAlloc(adbg, 32, false);
        cfg.trace_depth          = 2;
        DebugAllocator dbg       = DebugAllocatorInitWith(cfg);
        Allocator     *adbg      = ALLOCATOR_OF(&dbg);
    
        void *p  = AllocatorAlloc(adbg, 32, false);
        cfg.trace_depth          = 20;
        DebugAllocator dbg       = DebugAllocatorInitWith(cfg);
        Allocator     *adbg      = ALLOCATOR_OF(&dbg);
    
        void *p  = AllocatorAlloc(adbg, 32, false);
    bool test_ad1_stats_deallocations_increment(void) {
        DebugAllocator dbg  = DebugAllocatorInit();
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
        void *p  = AllocatorAlloc(adbg, 32, false);
    bool test_ad1_stats_bytes_in_use_partial_free(void) {
        DebugAllocator dbg  = DebugAllocatorInit();
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
        void *a  = AllocatorAlloc(adbg, 64, false);
    bool test_ad1_clean_roundtrip_no_false_overflow(void) {
        DebugAllocator dbg  = DebugAllocatorInit();
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
        u8  *buf = (u8 *)AllocatorAlloc(adbg, 32, false);
    bool test_ad1_double_free_aborts(void) {
        DebugAllocator dbg  = DebugAllocatorInit();
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
        void *p = AllocatorAlloc(adbg, 32, true);
    bool test_ad1_foreign_free_aborts(void) {
        DebugAllocator dbg  = DebugAllocatorInit();
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
        u8 junk[64];
    bool test_ad2_alloc_bumps_live_bytes(void) {
        DebugAllocator dbg  = DebugAllocatorInit();
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
        void *p  = AllocatorAlloc(adbg, 100, false);
    bool test_ad2_alloc_increments_allocations(void) {
        DebugAllocator dbg  = DebugAllocatorInit();
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
        void *p1 = AllocatorAlloc(adbg, 16, false);
    bool test_ad2_alloc_accumulates_bytes_requested(void) {
        DebugAllocator dbg  = DebugAllocatorInit();
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
        void *p1 = AllocatorAlloc(adbg, 30, false);
    bool test_ad2_alloc_bumps_stats_bytes_in_use(void) {
        DebugAllocator dbg  = DebugAllocatorInit();
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
        void *p  = AllocatorAlloc(adbg, 256, false);
    bool test_ad2_alloc_tracks_peak_value(void) {
        DebugAllocator dbg  = DebugAllocatorInit();
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
        void *p  = AllocatorAlloc(adbg, 512, false);
    bool test_ad2_peak_advances_on_first_alloc(void) {
        DebugAllocator dbg  = DebugAllocatorInit();
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
        void *p  = AllocatorAlloc(adbg, 333, false);
    bool test_ad2_peak_holds_historical_max(void) {
        DebugAllocator dbg  = DebugAllocatorInit();
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
        void *big = AllocatorAlloc(adbg, 1000, false);
    bool test_ad2_failed_alloc_counter(void) {
        DebugAllocator dbg  = DebugAllocatorInit();
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
        // Absurd size: the heap cannot serve it and returns NULL.
    bool test_ad2_trace_count_within_bounds(void) {
        DebugAllocator dbg  = DebugAllocatorInit(); // capture_traces, trace_depth=8
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
        // 30 levels of recursion guarantee the stack is deeper than the
        cfg.trace_depth          = 4; // below MAX_TRACE
        DebugAllocator dbg       = DebugAllocatorInitWith(cfg);
        Allocator     *adbg      = ALLOCATOR_OF(&dbg);
    
        void *p  = deep_alloc(adbg, 64, false, 30);
        cfg.trace_depth          = 32; // above MAX_TRACE -> must clamp to 16
        DebugAllocator dbg       = DebugAllocatorInitWith(cfg);
        Allocator     *adbg      = ALLOCATOR_OF(&dbg);
    
        void *p  = deep_alloc(adbg, 64, false, 40);
    bool test_ad2_full_width_write_is_clean(void) {
        DebugAllocator dbg  = DebugAllocatorInit();
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
        size n   = 48;
    bool test_ad2_zeroed_region_is_zero_and_sized(void) {
        DebugAllocator dbg  = DebugAllocatorInit();
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
        size n   = 200;
    bool test_ad2_hash_tracks_many_allocations(void) {
        DebugAllocator dbg  = DebugAllocatorInit();
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
        enum {
    bool test_ad2_resize_refuses_in_place(void) {
        DebugAllocator dbg  = DebugAllocatorInit();
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
        void *p  = AllocatorAlloc(adbg, 64, false);
    bool test_ad2_overflow_one_past_detected(void) {
        DebugAllocator dbg  = DebugAllocatorInit();
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
        size n   = 32;
    bool test_ad2_resize_validates_self(void) {
        DebugAllocator dbg  = DebugAllocatorInit();
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
        void *p = AllocatorAlloc(adbg, 16, false);
    bool test_ad3_remap_grow_preserves_full_old_width(void) {
        DebugAllocator dbg  = DebugAllocatorInit();
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
        u8 *p = (u8 *)AllocatorAlloc(adbg, 64, true);
    bool test_ad3_remap_shrink_copy_is_min_not_max(void) {
        DebugAllocator dbg  = DebugAllocatorInit();
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
        u8 *p = (u8 *)AllocatorAlloc(adbg, 64, true);
    bool test_ad3_remap_unknown_ptr_aborts(void) {
        DebugAllocator dbg  = DebugAllocatorInit();
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
        u8 junk[64];
    bool test_ad3_report_leaks_includes_trace_frames(void) {
        DebugAllocator dbg  = DebugAllocatorInit();
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
        void *p = AllocatorAlloc(adbg, 24, true);
        // point; the validated bit is still set, so structural runs.
        dbg.heap.base.__magic = 0xdeadbeefULL;
        Allocator *adbg       = ALLOCATOR_OF(&dbg);
        (void)AllocatorAlloc(adbg, 32, true); // structural -> bad heap magic LOG_FATAL
        return false;                         // unreachable
    bool test_ad3_structural_skipped_after_first_op(void) {
        DebugAllocator dbg  = DebugAllocatorInit();
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
        // First op clears the validated bit.
        // entry runs structural and exercises the pow2 check.
        dbg.base.alignment = 4;
        Allocator *adbg    = ALLOCATOR_OF(&dbg);
    
        void *p  = AllocatorAlloc(adbg, 32, true); // real: 4 is pow2 -> accepted
    bool test_ad3_structural_allows_live_allocation(void) {
        DebugAllocator dbg  = DebugAllocatorInit();
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
        void *p  = AllocatorAlloc(adbg, 48, true); // count=1, bytes_in_use=48
        // self->page, so only structural can catch this.
        dbg.page.base.__magic = 0xdeadbeefULL;
        Allocator *adbg       = ALLOCATOR_OF(&dbg);
        (void)AllocatorAlloc(adbg, 32, true); // structural -> bad page magic LOG_FATAL
        return false;                         // unreachable
        cfg.trace_depth          = 32; // above DEBUG_ALLOCATOR_MAX_TRACE (16)
        DebugAllocator dbg       = DebugAllocatorInitWith(cfg);
        Allocator     *adbg      = ALLOCATOR_OF(&dbg);
    
        af_deep_free(adbg, 25); // alloc+free ~25 frames deep
    bool test_blind_stats_bytes_in_use_underflow_clamps_zero(void) {
        DebugAllocator dbg  = DebugAllocatorInit();
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
        void *p  = AllocatorAlloc(adbg, 64, false);
    bool test_blind_report_leaks_emits_all_frames(void) {
        DebugAllocator dbg  = DebugAllocatorInit(); // capture_traces on, depth 8
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
        void *p  = AllocatorAlloc(adbg, 24, true);
    bool test_blind_report_leaks_no_extra_frame(void) {
        DebugAllocator dbg  = DebugAllocatorInit();
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
        void *p  = AllocatorAlloc(adbg, 24, true);
    
        DebugAllocator dbg  = DebugAllocatorInit();
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
        ArgParse p = ArgParseInit("prog", "an about line", adbg);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float value = float_from_u64(42, ALLOCATOR_OF(&alloc));
        Str   text  = FloatToStr(&value);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float value = float_from_i64(-42, ALLOCATOR_OF(&alloc));
        Str   text  = FloatToStr(&value);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Int   integer = IntFromStr("12345678901234567890", ALLOCATOR_OF(&alloc));
        Float value   = float_from_int(&integer, ALLOCATOR_OF(&alloc));
        Str   text    = FloatToStr(&value);
    
        Int   integer = IntFromStr("12345678901234567890", ALLOCATOR_OF(&alloc));
        Float value   = float_from_int(&integer, ALLOCATOR_OF(&alloc));
        Str   text    = FloatToStr(&value);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float value        = FloatFromStr("1234500e-2", ALLOCATOR_OF(&alloc));
        Int   result_value = IntInit(ALLOCATOR_OF(&alloc));
        Str   text         = StrInit(ALLOCATOR_OF(&alloc));
    
        Float value        = FloatFromStr("1234500e-2", ALLOCATOR_OF(&alloc));
        Int   result_value = IntInit(ALLOCATOR_OF(&alloc));
        Str   text         = StrInit(ALLOCATOR_OF(&alloc));
        Float value        = FloatFromStr("1234500e-2", ALLOCATOR_OF(&alloc));
        Int   result_value = IntInit(ALLOCATOR_OF(&alloc));
        Str   text         = StrInit(ALLOCATOR_OF(&alloc));
    
        bool result = FloatToInt(&result_value, &value);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float value        = FloatFromStr("123.45", ALLOCATOR_OF(&alloc));
        Int   result_value = IntFrom(99, ALLOCATOR_OF(&alloc));
    
        Float value        = FloatFromStr("123.45", ALLOCATOR_OF(&alloc));
        Int   result_value = IntFrom(99, ALLOCATOR_OF(&alloc));
    
        bool result = !FloatToInt(&result_value, &value);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float value        = FloatFromStr("-42", ALLOCATOR_OF(&alloc));
        Int   result_value = IntFrom(99, ALLOCATOR_OF(&alloc));
    
        Float value        = FloatFromStr("-42", ALLOCATOR_OF(&alloc));
        Int   result_value = IntFrom(99, ALLOCATOR_OF(&alloc));
    
        bool result = !FloatToInt(&result_value, &value);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float value = FloatFromStr("-123.45", ALLOCATOR_OF(&alloc));
        Str   text  = FloatToStr(&value);
        alloc.base.retry_limit = 5;
    
        Float value = FloatFromStr("-123.45", ALLOCATOR_OF(&alloc));
    
        ok = float_try_to_str(&text, &value, ALLOCATOR_OF(&alloc));
        Float value = FloatFromStr("-123.45", ALLOCATOR_OF(&alloc));
    
        ok = float_try_to_str(&text, &value, ALLOCATOR_OF(&alloc));
    
        bool result = ok && (ZstrCompare(StrBegin(&text), "-123.45") == 0) &&
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float value = FloatFromStr(FLOAT_TEST_VERY_LARGE_ONES, ALLOCATOR_OF(&alloc));
        Str   text  = FloatToStr(&value);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float value = FloatFromStr("1.2300e3", ALLOCATOR_OF(&alloc));
        Str   text  = FloatToStr(&value);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float parsed = FloatFromStr("12.3.4", ALLOCATOR_OF(&alloc));
        Float value  = FloatInit(ALLOCATOR_OF(&alloc));
        bool  result = !FloatTryFromStr(&value, "12.3.4");
    
        Float parsed = FloatFromStr("12.3.4", ALLOCATOR_OF(&alloc));
        Float value  = FloatInit(ALLOCATOR_OF(&alloc));
        bool  result = !FloatTryFromStr(&value, "12.3.4");
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        FloatFromStr((Zstr)NULL, ALLOCATOR_OF(&alloc));
        DefaultAllocatorDeinit(&alloc);
        return false;
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Float value = FloatInit(ALLOCATOR_OF(&alloc));
        FloatTryFromStr(&value, (Zstr)NULL);
        FloatDeinit(&value);
            g_fixture_heap_ready = true;
        }
        return ALLOCATOR_OF(&g_fixture_heap);
    }
        WriteFmt("Testing BitVecShrinkToFit\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Add some bits
        WriteFmt("Testing BitVecReserve\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Add some bits
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecReserve(&bv, 64);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecReserve(&bv, 64);
        WriteFmt("Testing BitVecSwap\n");
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Set up first bitvector
        WriteFmt("Testing BitVecClone\n");
    
        BitVec original = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Set up original bitvector
        alloc.base.retry_limit = 9;
    
        BitVec original = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVecPush(&original, true);
        WriteFmt("Testing BitVecShrinkToFit edge cases\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecReserve edge cases\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecSwap edge cases\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecClone edge cases\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        for (int cycle = 0; cycle < 10; cycle++) {
            BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
            BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        for (int cycle = 0; cycle < 10; cycle++) {
            BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
            BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
            // Add random-sized data
        WriteFmt("Testing BitVec swap NULL handling\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Test NULL pointer - should abort
        WriteFmt("Testing resize-grow clears stale tail bits\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Fill a full byte with ones so bits 5,6,7 are set in the backing byte.
        WriteFmt("Testing BitVecReserve with zero capacity returns true\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        bool result = (BitVecReserve(&bv, 0) == true);
        WriteFmt("Testing BitVecShrinkToFit preserves bits on a large vector\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // 400 bits => doubling growth yields capacity 512, byte_size 64,
        WriteFmt("Testing BitVecShrinkToFit keeps the vector structurally valid\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        for (int i = 0; i < 400; i++) {
        WriteFmt("Testing BitVecSwap keeps a swapped-in large vector valid\n");
    
        BitVec small = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec large = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec small = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec large = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVecPush(&small, true);
        WriteFmt("Testing BitVecSwap aborts on an invalid second argument\n");
    
        BitVec good = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&good, true);
        WriteFmt("Testing BitVecTryClone aborts on an invalid source\n");
    
        BitVec out = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bad = {0}; // magic 0 => invalid bitvec
    
        // Test basic initialization
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Check initial state
        WriteFmt("Testing BitVecDeinit\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Add some data to make sure deinitialization works with allocated memory
        WriteFmt("Testing BitVecReserve\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Reserve space for 50 bits
        WriteFmt("Testing BitVecClear\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Add some data
        WriteFmt("Testing BitVecResize\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Add some initial data
    
        // Test multiple initializations
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv3 = BitVecInit(ALLOCATOR_OF(&alloc));
        // Test multiple initializations
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv3 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv3 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        bool result = (BitVecLen(&bv1) == 0) && (BitVecLen(&bv2) == 0) && (BitVecLen(&bv3) == 0);
        WriteFmt("Testing BitVecReserve edge cases\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecReu64 edge cases\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecClear edge cases\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        // Test multiple init/deinit cycles
        for (int cycle = 0; cycle < 100; cycle++) {
            BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
            // Add some data
        // failure rather than aborting. The Must variant aborts, so use it here
        // to validate the deadend abort path.
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVecMustReserve(&bv, SIZE_MAX);
        // failure rather than aborting. The Must variant aborts, so use it here
        // to validate the deadend abort path.
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVecMustResize(&bv, SIZE_MAX);
        WriteFmt("Testing BitVec get bounds checking\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Test get from empty bitvec - should abort
        WriteFmt("Testing BitVec set bounds checking\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Test set on empty bitvec - should abort
        WriteFmt("Testing BitVec flip bounds checking\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Test flip on empty bitvec - should abort
        WriteFmt("Testing BitVec get with large out-of-bounds index\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv, true);
        BitVecPush(&bv, false);
        WriteFmt("Testing BitVec set with large out-of-bounds index\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv, true);
        BitVecPush(&bv, false);
        WriteFmt("Testing BitVec flip with edge case out-of-bounds index\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
        for (int i = 0; i < 10; i++) {
            BitVecPush(&bv, i % 2 == 0);
        WriteFmt("Testing BitVec get with maximum index value\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv, true);
        WriteFmt("Testing BitVecEquals\n");
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv3 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv3 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv3 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Test equal empty bitvectors
        WriteFmt("Testing BitVecCompare\n");
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Test equal bitvectors
        WriteFmt("Testing BitVecLexCompare\n");
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Test lexicographic comparison
        WriteFmt("Testing BitVecNumericalCompare\n");
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Create bitvectors representing different numbers
        WriteFmt("Testing BitVecWeightCompare\n");
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // bv1: 111 (3 ones)
        WriteFmt("Testing BitVecIsSubset\n");
    
        BitVec subset   = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec superset = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec subset   = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec superset = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Create superset: 1111
        WriteFmt("Testing BitVecSignedCompare\n");
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Test positive vs negative (MSB is sign bit)
        WriteFmt("Testing BitVecIsSuperset\n");
    
        BitVec superset = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec subset   = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec superset = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec subset   = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Create superset: 1111
        WriteFmt("Testing BitVecOverlaps\n");
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Create overlapping bitvectors
        WriteFmt("Testing BitVecDisjoint and BitVecIntersects\n");
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Create disjoint bitvectors
        WriteFmt("Testing BitVecEqualsRange\n");
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Create test patterns
        WriteFmt("Testing BitVecCompareRange\n");
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Create test patterns
        WriteFmt("Testing BitVecIsLexicographicallyLess and BitVecIsNumericallyLess\n");
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Test lexicographic comparison
        WriteFmt("Testing BitVecIsSorted\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Test empty bitvector (should be sorted)
        WriteFmt("Testing BitVec compare edge cases\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVec set operations edge cases\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVec comprehensive comparison operations\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        // Test transitivity: if A < B and B < C, then A < C
        BitVec bv3 = BitVecInit(ALLOCATOR_OF(&alloc));
        // bv3: larger than bv2
        for (int i = 0; i < 8; i++) {
    
        // Test subset/superset consistency
        BitVec subset   = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec superset = BitVecInit(ALLOCATOR_OF(&alloc));
        // Test subset/superset consistency
        BitVec subset   = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec superset = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Create actual subset/superset relationship
        WriteFmt("Testing BitVec large-scale comparison operations\n");
    
        BitVec large1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec large2 = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec large1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec large2 = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        // Verify signed vs unsigned comparison differences
        BitVec pos = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec neg = BitVecInit(ALLOCATOR_OF(&alloc));
        // Verify signed vs unsigned comparison differences
        BitVec pos = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec neg = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Positive number (MSB = 0): 01111111
        WriteFmt("Testing BitVec compare NULL pointer handling\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Test NULL pointer - should abort
        WriteFmt("Testing BitVec range operations NULL handling\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Test NULL pointer in range operations - should abort
        WriteFmt("Testing BitVec range operations bounds checking\n");
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Create small bitvectors
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec a = BitVecInit(base);
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec a = BitVecInit(base);
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        Map(BitVec, u64) counts = MapInit(bitvec_hash, bitvec_compare, &alloc);
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec a = BitVecInit(base);
        WriteFmt("Testing BitVecEquals rejects bad second operand\n");
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bad = {0};
        WriteFmt("Testing BitVecEqualsRange rejects bad second operand\n");
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bad = {0};
    static bool test_hash_xor_byte_distinguishes(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec a = BitVecInit(base); // byte 0x00
    static bool test_hash_length_mix_mul_distinguishes(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec a = BitVecInit(base); // 10101010
    static bool test_hash_all_bytes_folded(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec a = BitVecInit(base); // byte0 = 0xFF, byte1 = 0x00
    static bool test_compare_null_lhs_aborts(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec bv = BitVecInit(base);
    static bool test_compare_null_rhs_aborts(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec bv = BitVecInit(base);
    static bool test_compare_range_null_lhs_aborts(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec bv = BitVecInit(base);
    static bool test_compare_range_null_rhs_aborts(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec bv = BitVecInit(base);
    static bool test_numerical_compare_null_lhs_aborts(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec bv = BitVecInit(base);
    static bool test_numerical_high_bit_not_truncated(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec bv1 = BitVecInit(base);
    static bool test_signed_neg_vs_empty(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec neg   = BitVecInit(base);
    static bool test_signed_empty_vs_neg(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec empty = BitVecInit(base);
    static bool test_signed_sign1_le_mutant(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec neg = BitVecInit(base);
    static bool test_signed_sign1_ge_no_abort(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec empty = BitVecInit(base);
    static bool test_signed_sign2_ge_no_abort(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec neg   = BitVecInit(base);
    static bool test_signed_two_equal_negatives(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec a = BitVecInit(base);
    static bool test_signed_two_negatives_magnitude_flip(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec a = BitVecInit(base);
    static bool test_numerical_null_bv2(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec bv = BitVecInit(base);
    static bool test_signed_null_bv1(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec bv = BitVecInit(base);
    static bool test_signed_null_bv2(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec bv = BitVecInit(base);
    static bool test_subset_null_bv1(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec bv = BitVecInit(base);
    bool test_subset_skips_high_positions(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        WriteFmt("Testing BitVecIsSubset scans past index 42\n");
    bool test_subset_bv1_short_no_abort(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        WriteFmt("Testing BitVecIsSubset with shorter bv1 stays in bounds\n");
    bool test_subset_bv2_short_no_abort(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        WriteFmt("Testing BitVecIsSubset with shorter bv2 stays in bounds\n");
    bool test_disjoint_scans_all_positions(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        WriteFmt("Testing BitVecDisjoint scans beyond position 0\n");
    bool test_subset_null_bv2_aborts(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        WriteFmt("Testing BitVecIsSubset rejects NULL bv2\n");
    bool test_disjoint_null_bv1_aborts(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        WriteFmt("Testing BitVecDisjoint rejects NULL bv1\n");
    bool test_disjoint_null_bv2_aborts(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        WriteFmt("Testing BitVecDisjoint rejects NULL bv2\n");
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        BitVec a = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec b = BitVecInit(ALLOCATOR_OF(&alloc));
        for (int i = 0; i < 256; i++) {
    
        BitVec a = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec b = BitVecInit(ALLOCATOR_OF(&alloc));
        for (int i = 0; i < 256; i++) {
            BitVecPush(&a, false);
        WriteFmt("Testing BitVecPush\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Push some bits
        WriteFmt("Testing BitVecInsert (single bit)\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Insert at index 0 (empty bitvector)
        WriteFmt("Testing BitVecInsertRange\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Create target bitvector
        WriteFmt("Testing BitVecInsertMultiple\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Start with some bits
        WriteFmt("Testing BitVecInsertPattern\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Start with some bits
    
        // Test with different pattern - 0x05 (0101 in binary) using only 3 bits
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv2, true);
        WriteFmt("Testing BitVecInsertRange edge cases\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecInsertMultiple edge cases\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec empty  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec empty  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec empty  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecInsertPattern edge cases\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVec insert invalid range handling\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Test inserting beyond capacity limit - should abort
        WriteFmt("Testing BitVecInsertRange shifts existing tail bits\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Original: [1, 0, 1, 1]
        WriteFmt("Testing BitVecInsertMultiple shifts existing tail bits\n");
    
        BitVec bv    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec other = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec other = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // bv: [1, 0, 1]
        WriteFmt("Testing BitVecInsertMultiple NULL bv validation\n");
    
        BitVec other = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&other, true);
        WriteFmt("Testing BitVecInsertMultiple NULL other validation\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv, true);
        WriteFmt("Testing BitVecFindPattern(NULL, pattern) - should fatal\n");
    
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&pattern, true);
        WriteFmt("Testing BitVecFindPattern(source, NULL) - should fatal\n");
    
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&source, true);
        BitVecPush(&source, false);
        WriteFmt("Testing BitVecFindLastPattern(NULL, pattern) - should fatal\n");
    
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&pattern, true);
        WriteFmt("Testing BitVecFindLastPattern(source, NULL) - should fatal\n");
    
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&source, true);
        BitVecPush(&source, false);
        WriteFmt("Testing BitVecFindAllPattern(source, NULL, results, 10) - should fatal\n");
    
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        size   results[10];
        BitVecPush(&source, true);
        WriteFmt("Testing BitVecFindAllPattern(source, pattern, NULL, 10) - should fatal\n");
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&source, true);
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&source, true);
        BitVecPush(&source, false);
        WriteFmt("Testing BitVecFindAllPattern(source, pattern, results, 0) - should fatal\n");
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        size   results[10];
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        size   results[10];
        BitVecPush(&source, true);
    
        WriteFmt("Testing BitVecStartsWith(NULL, prefix) - should fatal\n");
        BitVec prefix = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&prefix, true);
        BitVecStartsWith(NULL, &prefix);
    
        WriteFmt("Testing BitVecStartsWith(source, NULL) - should fatal\n");
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&source, true);
        BitVecStartsWith(&source, NULL);
    
        WriteFmt("Testing BitVecEndsWith(NULL, suffix) - should fatal\n");
        BitVec suffix = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&suffix, true);
        BitVecEndsWith(NULL, &suffix);
    
        WriteFmt("Testing BitVecEndsWith(source, NULL) - should fatal\n");
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&source, true);
        BitVecEndsWith(&source, NULL);
    
        WriteFmt("Testing BitVecContainsAt(NULL, pattern, 0) - should fatal\n");
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&pattern, true);
        BitVecContainsAt(NULL, &pattern, 0);
    
        WriteFmt("Testing BitVecContainsAt(source, NULL, 0) - should fatal\n");
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&source, true);
        BitVecContainsAt(&source, NULL, 0);
    
        WriteFmt("Testing BitVecMatches(NULL, pattern, wildcard) - should fatal\n");
        BitVec pattern  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec wildcard = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&pattern, true);
        WriteFmt("Testing BitVecMatches(NULL, pattern, wildcard) - should fatal\n");
        BitVec pattern  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec wildcard = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&pattern, true);
        BitVecPush(&wildcard, false);
    
        WriteFmt("Testing BitVecRegexMatch(source, NULL) - should fatal\n");
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&source, true);
        BitVecRegexMatch(&source, (Zstr)NULL);
        DefaultAllocator alloc = DefaultAllocatorInit();
        WriteFmt("Testing BitVecPrefixMatch(NULL, patterns, 1) - should fatal\n");
        BitVecs vp = VecInitWithDeepCopy(NULL, BitVecDeinit, ALLOCATOR_OF(&alloc));
        BitVecPush(VecPtrAt(&vp, 0), true);
        BitVecPrefixMatch(NULL, &vp);
    
        WriteFmt("Testing BitVecPrefixMatch(source, NULL, 1) - should fatal\n");
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&source, true);
        BitVecPrefixMatch(&source, NULL);
        DefaultAllocator alloc = DefaultAllocatorInit();
        WriteFmt("Testing BitVecSuffixMatch(NULL, patterns, 1) - should fatal\n");
        BitVecs vp = VecInitWithDeepCopy(NULL, BitVecDeinit, ALLOCATOR_OF(&alloc));
        BitVecPush(VecPtrAt(&vp, 0), true);
        BitVecSuffixMatch(NULL, &vp);
    
        WriteFmt("Testing BitVecSuffixMatch(source, NULL, 1) - should fatal\n");
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&source, true);
        BitVecSuffixMatch(&source, NULL);
    bool test_find_all_pattern_vec_null_bv_aborts(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        WriteFmt("Testing BitVecFindAllPattern (vec) with NULL bitvector\n");
    bool test_find_all_pattern_vec_null_pattern_aborts(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        WriteFmt("Testing BitVecFindAllPattern (vec) with NULL pattern\n");
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&pattern, true);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&source, true);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&pattern, true);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&source, true);
        WriteFmt("Testing BitVecReplace(src, old, NULL) with old absent - should fatal\n");
    
        BitVec source      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec old_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        push_bits(&source, "0000");
    
        BitVec source      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec old_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        push_bits(&source, "0000");
        push_bits(&old_pattern, "111");             // not present in source
    
        BitVec bad         = {0}; // magic mismatch -> ValidateBitVec aborts
        BitVec old_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec new_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        push_bits(&old_pattern, "1");
        BitVec bad         = {0}; // magic mismatch -> ValidateBitVec aborts
        BitVec old_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec new_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        push_bits(&old_pattern, "1");
        push_bits(&new_pattern, "0");
        WriteFmt("Testing BitVecReplaceAll(empty, NULL, new) - should fatal\n");
    
        BitVec source      = BitVecInit(ALLOCATOR_OF(&alloc)); // empty
        BitVec new_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        push_bits(&new_pattern, "0");
    
        BitVec source      = BitVecInit(ALLOCATOR_OF(&alloc)); // empty
        BitVec new_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        push_bits(&new_pattern, "0");
        WriteFmt("Testing BitVecReplaceAll(empty, old, NULL) - should fatal\n");
    
        BitVec source      = BitVecInit(ALLOCATOR_OF(&alloc)); // empty
        BitVec old_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        push_bits(&old_pattern, "1");
    
        BitVec source      = BitVecInit(ALLOCATOR_OF(&alloc)); // empty
        BitVec old_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        push_bits(&old_pattern, "1");
    static bool test_matches_null_pattern_aborts(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec source   = BitVecInit(base);
    static bool test_matches_null_wildcard_aborts(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec source  = BitVecInit(base);
    static bool test_fuzzy_null_source_aborts(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec pattern = BitVecInit(base);
    static bool test_fuzzy_null_pattern_aborts(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec source = BitVecInit(base);
        WriteFmt("Testing BitVecPrefixMatch(NULL, empty) - should fatal\n");
    
        BitVecs patterns = VecInitWithDeepCopy(NULL, BitVecDeinit, ALLOCATOR_OF(&alloc));
    
        // Empty patterns: with validation present this aborts on the NULL bv;
        WriteFmt("Testing BitVecSuffixMatch(NULL, empty) - should fatal\n");
    
        BitVecs patterns = VecInitWithDeepCopy(NULL, BitVecDeinit, ALLOCATOR_OF(&alloc));
    
        // Empty patterns: with validation present this aborts on the NULL bv;
        WriteFmt("Testing BitVecRunLengths with NULL runs array\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv, true);
        bool values[5];
        WriteFmt("Testing BitVecRunLengths with NULL values array\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv, true);
        u64 runs[5];
        WriteFmt("Testing BitVecRunLengths with zero max_runs\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv, true);
        u64  runs[5];
        // no public setter exists -- the whole point of this test is to plant
        // length>0 with data==NULL so ValidateBitVec aborts in the foreach prologue.
        BitVec bv   = BitVecInit(ALLOCATOR_OF(&alloc));
        bv.length   = 5;
        bv.capacity = 10;
    bool test_run_lengths_vec_null_bv_aborts(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        WriteFmt("Testing BitVecRunLengths (vec) with NULL bitvector\n");
        DefaultAllocator alloc = DefaultAllocatorInit();
        typedef List(int) LI;
        LI li = ListInit(ALLOCATOR_OF(&alloc));
        ListForeach(&li, i) {
            (void)i;
        WriteFmt("Testing BitVecForeachIdx macro\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Add test pattern: true, false, true, false
        WriteFmt("Testing BitVecForeach macro\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Add test pattern: true, false, true
        WriteFmt("Testing BitVecForeachReverseIdx macro\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Add test pattern: true, false, true, false
        WriteFmt("Testing BitVecForeachReverse macro\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Add test pattern: true, false, true
        WriteFmt("Testing BitVecForeachInRangeIdx macro\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Add test pattern: true, false, true, false, true
        WriteFmt("Testing BitVecForeachInRange macro\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Add test pattern: false, true, true, false, true
        WriteFmt("Testing BitVec foreach edge cases\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        int    count  = 0;
        WriteFmt("Testing BitVec foreach idx edge cases\n");
    
        BitVec bv       = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result   = true;
        u64    last_idx = SIZE_MAX;
        WriteFmt("Testing BitVec foreach reverse edge cases\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVec foreach range edge cases\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        for (int sz = 0; sz < 100; sz += 10) {
            BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
            // Create bitvec of varying sz
        WriteFmt("Testing BitVecRunLengths basic functionality\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    bool test_bitvec_run_lengths_vec(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        WriteFmt("Testing BitVecRunLengths Vec form\n");
    
        // Test 1: Empty bitvector
        BitVec empty_bv = BitVecInit(ALLOCATOR_OF(&alloc));
        u64    runs[5];
        bool   values[5];
    
        // Test 2: Single bit (true)
        BitVec single_bv = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&single_bv, true);
        count  = BitVecRunLengths(&single_bv, runs, values, 5);
    
        // Test 3: Single bit (false)
        BitVec single_false_bv = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&single_false_bv, false);
        count  = BitVecRunLengths(&single_false_bv, runs, values, 5);
    
        // Test 4: All same bits (all true)
        BitVec all_true_bv = BitVecInit(ALLOCATOR_OF(&alloc));
        for (int i = 0; i < 10; i++) {
            BitVecPush(&all_true_bv, true);
    
        // Test 5: Alternating bits (0101010)
        BitVec alternating_bv = BitVecInit(ALLOCATOR_OF(&alloc));
        for (int i = 0; i < 7; i++) {
            BitVecPush(&alternating_bv, i % 2 == 0);
        WriteFmt("Testing BitVecRunLengths boundary conditions\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        // Test with large bitvector
        BitVec large_bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Create pattern that results in many runs
    
        // Create a bitvector
        BitVec bitvec = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Check initial state
    
        // Create a valid bitvector
        BitVec bitvec = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // This should not abort
        WriteFmt("Testing BitVecAnd\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Set up first bitvector: 1101
        WriteFmt("Testing BitVecOr\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Set up first bitvector: 1100
        WriteFmt("Testing BitVecXor\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Set up first bitvector: 1100
        WriteFmt("Testing BitVecNot\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Set up bitvector: 1010
        WriteFmt("Testing BitVecShiftLeft\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Set up bitvector: 1011 (indices 0,1,2,3)
        WriteFmt("Testing BitVecShiftRight\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Set up bitvector: 1011
        WriteFmt("Testing BitVecRotateLeft\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Set up bitvector: 1011
        WriteFmt("Testing BitVecRotateRight\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Set up bitvector: 1011
        WriteFmt("Testing BitVecReverse\n");
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Set up bitvector: 1011
        WriteFmt("Testing BitVec shift edge cases\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVec rotate edge cases\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVec bitwise operations edge cases\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        // Test operations on empty bitvecs
        BitVec result_bv = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecAnd(&result_bv, &bv1, &bv2);
        result = result && (BitVecLen(&result_bv) == 0);
        WriteFmt("Testing BitVecReverse edge cases\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVec comprehensive bitwise operations\n");
    
        BitVec bv1         = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2         = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result      = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv1         = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2         = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result      = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   test_result = true;
        BitVec bv1         = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2         = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result      = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   test_result = true;
        WriteFmt("Testing BitVec comprehensive shift operations\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVec comprehensive rotate operations\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVec bitwise identity operations\n");
    
        BitVec bv1         = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2         = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result      = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv1         = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2         = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result      = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   test_result = true;
        BitVec bv1         = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2         = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result      = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   test_result = true;
        WriteFmt("Testing BitVec bitwise commutative properties\n");
    
        BitVec bv1         = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2         = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result1     = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv1         = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2         = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result1     = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result2     = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv1         = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2         = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result1     = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result2     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   test_result = true;
        BitVec bv2         = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result1     = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result2     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   test_result = true;
        WriteFmt("Testing BitVec bitwise operations with large patterns\n");
    
        BitVec bv1         = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2         = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result      = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv1         = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2         = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result      = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   test_result = true;
        BitVec bv1         = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2         = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result      = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   test_result = true;
        WriteFmt("Testing BitVecOr widens past shorter operand a\n");
    
        BitVec a      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec b      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec a      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec b      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec a      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec b      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // a = 10 (len 2)
        WriteFmt("Testing BitVecXor widens past shorter operand a\n");
    
        BitVec a      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec b      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec a      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec b      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec a      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec b      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // a = 10 (len 2)
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
        for (int i = 0; i < 8; i++) {
            BitVecPush(&bv, true);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        BitVec bv = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv, true);  // bit 0
        BitVecPush(&bv, true);  // bit 1
    bool test_blind_rotate_right_exact(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        BitVec           bv    = BitVecInit(ALLOCATOR_OF(&alloc));
    
        bool pat[5] = {true, false, false, true, true};
    
        DebugAllocator dbg  = DebugAllocatorInit();
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
        BitVec bv = BitVecInit(adbg);
    
        DebugAllocator dbg  = DebugAllocatorInitWith(lean_dbg_cfg());
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
        BitVec bv = BitVecInit(adbg);
        WriteFmt("Testing BitVec bitwise operations NULL handling\n");
    
        BitVec bv  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Test NULL pointer - should abort
        WriteFmt("Testing BitVec AND with NULL result handling\n");
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv1, true);
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv1, true);
        BitVecPush(&bv2, false);
        WriteFmt("Testing BitVec OR with NULL operand handling\n");
    
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Test NULL operand - should abort
        WriteFmt("Testing BitVec XOR with NULL second operand handling\n");
    
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Test NULL second operand - should abort
        WriteFmt("Testing BitVec NOT with NULL handling\n");
    
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Test NULL operand - should abort
        WriteFmt("Testing BitVecAnd rejects bad third operand\n");
    
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec a      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bad    = {0};
    
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec a      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bad    = {0};
        WriteFmt("Testing BitVecAnd rejects bad second operand\n");
    
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec b      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bad    = {0};
    
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec b      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bad    = {0};
        WriteFmt("Testing BitVecOr rejects bad second operand\n");
    
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec b      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bad    = {0};
    
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec b      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bad    = {0};
        WriteFmt("Testing BitVecXor rejects bad third operand\n");
    
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec a      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bad    = {0};
    
        BitVec result = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec a      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bad    = {0};
        WriteFmt("Testing basic BitVec pattern functions\n");
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
        WriteFmt("Testing BitVecFindPattern function\n");
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
        WriteFmt("Testing BitVecFindLastPattern function\n");
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
        WriteFmt("Testing BitVecFindAllPattern function\n");
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
    bool test_bitvec_find_all_pattern_vec(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        WriteFmt("Testing BitVecFindAllPattern Vec form\n");
        WriteFmt("Testing BitVec pattern edge cases\n");
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
        WriteFmt("Testing BitVec pattern stress tests\n");
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
        WriteFmt("Testing BitVecStartsWith basic functionality\n");
    
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec prefix = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec prefix = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecStartsWith edge cases\n");
    
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec prefix = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec prefix = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecEndsWith basic functionality\n");
    
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec suffix = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec suffix = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecEndsWith edge cases\n");
    
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec suffix = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec suffix = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecFindPattern basic functionality\n");
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
        WriteFmt("Testing BitVecContainsAt basic functionality\n");
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
        WriteFmt("Testing BitVecContainsAt edge cases\n");
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
        WriteFmt("Testing BitVecCountPattern basic functionality\n");
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
        WriteFmt("Testing BitVecRFindPattern basic functionality\n");
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
        WriteFmt("Testing BitVecReplace basic functionality\n");
    
        BitVec source      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec old_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec new_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec source      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec old_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec new_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result      = true;
        BitVec source      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec old_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec new_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result      = true;
        WriteFmt("Testing BitVecReplaceAll basic functionality\n");
    
        BitVec source      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec old_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec new_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec source      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec old_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec new_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result      = true;
        BitVec source      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec old_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec new_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result      = true;
        WriteFmt("Testing BitVecMatches basic functionality\n");
    
        BitVec source   = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec wildcard = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec source   = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec wildcard = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result   = true;
        BitVec source   = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec wildcard = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result   = true;
        WriteFmt("Testing BitVecFuzzyMatch basic functionality\n");
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
        WriteFmt("Testing BitVecRegexMatch basic functionality\n");
    
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecPrefixMatch basic functionality\n");
    
        BitVec  source   = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecs patterns = VecInitWithDeepCopy(NULL, BitVecDeinit, ALLOCATOR_OF(&alloc));
        bool    result   = true;
    
        BitVec  source   = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecs patterns = VecInitWithDeepCopy(NULL, BitVecDeinit, ALLOCATOR_OF(&alloc));
        bool    result   = true;
        BitVec *p2 = VecPtrAt(&patterns, 2);
    
        *p0 = BitVecInit(ALLOCATOR_OF(&alloc));
        *p1 = BitVecInit(ALLOCATOR_OF(&alloc));
        *p2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        *p0 = BitVecInit(ALLOCATOR_OF(&alloc));
        *p1 = BitVecInit(ALLOCATOR_OF(&alloc));
        *p2 = BitVecInit(ALLOCATOR_OF(&alloc));
        *p0 = BitVecInit(ALLOCATOR_OF(&alloc));
        *p1 = BitVecInit(ALLOCATOR_OF(&alloc));
        *p2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Pattern 0: 111 (should not match)
        WriteFmt("Testing BitVecSuffixMatch basic functionality\n");
    
        BitVec  source   = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecs patterns = VecInitWithDeepCopy(NULL, BitVecDeinit, ALLOCATOR_OF(&alloc));
        bool    result   = true;
    
        BitVec  source   = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecs patterns = VecInitWithDeepCopy(NULL, BitVecDeinit, ALLOCATOR_OF(&alloc));
        bool    result   = true;
        BitVec *p2 = VecPtrAt(&patterns, 2);
    
        *p0 = BitVecInit(ALLOCATOR_OF(&alloc));
        *p1 = BitVecInit(ALLOCATOR_OF(&alloc));
        *p2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        *p0 = BitVecInit(ALLOCATOR_OF(&alloc));
        *p1 = BitVecInit(ALLOCATOR_OF(&alloc));
        *p2 = BitVecInit(ALLOCATOR_OF(&alloc));
        *p0 = BitVecInit(ALLOCATOR_OF(&alloc));
        *p1 = BitVecInit(ALLOCATOR_OF(&alloc));
        *p2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // Pattern 0: 111 (should not match)
    bool test_find_last_pattern_exact_length_match(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec source  = BitVecInit(base);
    bool test_find_all_pattern_vec_exact_length_match(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec source  = BitVecInit(base);
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec suffix = BitVecInit(ALLOCATOR_OF(&alloc));
        push_bits(&source, "101");
    
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec suffix = BitVecInit(ALLOCATOR_OF(&alloc));
        push_bits(&source, "101");
        push_bits(&suffix, "101");
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        push_bits(&source, "101");
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        push_bits(&source, "101");
        push_bits(&pattern, "101");
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        push_bits(&source, "101");
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        push_bits(&source, "101");
        push_bits(&pattern, "101");
        WriteFmt("Testing BitVecRFindPattern window-condition (ge_to_lt)\n");
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
        WriteFmt("Testing BitVecRFindPattern window-condition (add_to_sub)\n");
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
        WriteFmt("Testing BitVecRFindPattern window-value (add_to_sub)\n");
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
        WriteFmt("Testing BitVecRFindPattern loop-seed (add_to_sub)\n");
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
        WriteFmt("Testing BitVecRFindPattern loop-guard (gt_to_ge)\n");
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
    
        BitVec source  = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result  = true;
        WriteFmt("Testing BitVecReplaceAll found-flag init\n");
    
        BitVec source      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec old_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec new_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec source      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec old_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec new_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result      = true;
        BitVec source      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec old_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec new_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result      = true;
        WriteFmt("Testing BitVecReplaceAll forward-scan direction\n");
    
        BitVec source      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec old_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec new_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec source      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec old_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec new_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result      = true;
        BitVec source      = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec old_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec new_pattern = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result      = true;
    static bool test_replace_all_absent_no_change(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec source = BitVecInit(base);
    static bool test_replace_all_inserts_new_bits(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec source = BitVecInit(base);
    static bool test_matches_mismatch_returns_false(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec source   = BitVecInit(base);
    static bool test_fuzzy_equal_length_match(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec source  = BitVecInit(base);
    static bool test_fuzzy_match_position(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec source  = BitVecInit(base);
    static bool test_fuzzy_no_match_completes_loop(void) {
        DefaultAllocator alloc = DefaultAllocatorInit();
        Allocator       *base  = ALLOCATOR_OF(&alloc);
    
        BitVec source  = BitVecInit(base);
        WriteFmt("Testing bitvec_regex_match_str returns false on non-match\n");
    
        BitVec source = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        DebugAllocator dbg  = DebugAllocatorInitWith(lean_dbg_cfg());
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
        BitVec bv = BitVecInit(adbg);
    
        DebugAllocator dbg  = DebugAllocatorInitWith(lean_dbg_cfg());
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
        DefaultAllocator palloc = DefaultAllocatorInit();
    
        DefaultAllocator palloc = DefaultAllocatorInit();
        Allocator       *pbase  = ALLOCATOR_OF(&palloc);
    
        BitVec bv = BitVecInit(adbg);
        WriteFmt("Testing BitVecHammingDistance basic functionality\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecHammingDistance edge cases\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecJaccardSimilarity basic functionality\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecJaccardSimilarity edge cases\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecCosineSimilarity basic functionality\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecCosineSimilarity edge cases\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecDotProduct basic functionality\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecDotProduct edge cases\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecEditDistance basic functionality\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecEditDistance edge cases\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecCorrelation basic functionality\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecCorrelation edge cases\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecEntropy basic functionality\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecEntropy edge cases\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecAlignmentScore basic functionality\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecAlignmentScore edge cases\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecBestAlignment basic functionality\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecBestAlignment edge cases\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVec Math stress tests\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        // Test edit distance with smaller vectors (expensive operation)
        BitVec small1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec small2 = BitVecInit(ALLOCATOR_OF(&alloc));
        for (int i = 0; i < 50; i++) {
        // Test edit distance with smaller vectors (expensive operation)
        BitVec small1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec small2 = BitVecInit(ALLOCATOR_OF(&alloc));
        for (int i = 0; i < 50; i++) {
            BitVecPush(&small1, i % 2 == 0);
    
        WriteFmt("Testing BitVecHammingDistance(NULL, bv2) - should fatal\n");
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv2, true);
        BitVecHammingDistance(NULL, &bv2);
    
        WriteFmt("Testing BitVecHammingDistance(bv1, NULL) - should fatal\n");
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv1, true);
        BitVecHammingDistance(&bv1, NULL);
    
        WriteFmt("Testing BitVecJaccardSimilarity(NULL, bv2) - should fatal\n");
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv2, true);
        BitVecJaccardSimilarity(NULL, &bv2);
    
        WriteFmt("Testing BitVecJaccardSimilarity(bv1, NULL) - should fatal\n");
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv1, true);
        BitVecJaccardSimilarity(&bv1, NULL);
    
        WriteFmt("Testing BitVecCosineSimilarity(NULL, bv2) - should fatal\n");
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv2, true);
        BitVecCosineSimilarity(NULL, &bv2);
    
        WriteFmt("Testing BitVecCosineSimilarity(bv1, NULL) - should fatal\n");
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv1, true);
        BitVecCosineSimilarity(&bv1, NULL);
    
        WriteFmt("Testing BitVecDotProduct(NULL, bv2) - should fatal\n");
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv2, true);
        BitVecDotProduct(NULL, &bv2);
    
        WriteFmt("Testing BitVecDotProduct(bv1, NULL) - should fatal\n");
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv1, true);
        BitVecDotProduct(&bv1, NULL);
    
        WriteFmt("Testing BitVecEditDistance(NULL, bv2) - should fatal\n");
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv2, true);
        BitVecEditDistance(NULL, &bv2);
    
        WriteFmt("Testing BitVecEditDistance(bv1, NULL) - should fatal\n");
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv1, true);
        BitVecEditDistance(&bv1, NULL);
    
        WriteFmt("Testing BitVecCorrelation(NULL, bv2) - should fatal\n");
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv2, true);
        BitVecCorrelation(NULL, &bv2);
    
        WriteFmt("Testing BitVecCorrelation(bv1, NULL) - should fatal\n");
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv1, true);
        BitVecCorrelation(&bv1, NULL);
    
        WriteFmt("Testing BitVecAlignmentScore(NULL, bv2, 1, -1) - should fatal\n");
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv2, true);
        BitVecAlignmentScore(NULL, &bv2, 1, -1);
    
        WriteFmt("Testing BitVecAlignmentScore(bv1, NULL, 1, -1) - should fatal\n");
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv1, true);
        BitVecAlignmentScore(&bv1, NULL, 1, -1);
    
        WriteFmt("Testing BitVecBestAlignment(NULL, bv2) - should fatal\n");
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv2, true);
        BitVecBestAlignment(NULL, &bv2);
    
        WriteFmt("Testing BitVecBestAlignment(bv1, NULL) - should fatal\n");
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&bv1, true);
        BitVecBestAlignment(&bv1, NULL);
        WriteFmt("Testing BitVecJaccardSimilarity guard only fires when both empty\n");
    
        BitVec empty = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec one   = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&one, true);
    
        BitVec empty = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec one   = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&one, true);
        WriteFmt("Testing BitVecJaccardSimilarity with bv1 shorter than bv2\n");
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // bv1 = {1}, bv2 = {1, 0}. Intersection 1 (pos 0), union 1 -> 1.0.
        WriteFmt("Testing BitVecJaccardSimilarity with bv2 shorter than bv1\n");
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // bv1 = {1, 0}, bv2 = {1}. Intersection 1 (pos 0), union 1 -> 1.0.
        WriteFmt("Testing BitVecJaccardSimilarity reads bv2 bits in valid region\n");
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        // bv1 = {0, 0}, bv2 = {1, 1}. Intersection 0, union 2 -> 0.0.
        WriteFmt("Testing BitVecEditDistance column-0 base case\n");
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVecPush(&bv1, false);
        WriteFmt("Testing BitVecEditDistance deletion term\n");
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVecPush(&bv1, false);
        // exact size the empty->5 distance will recycle, guaranteeing the stale
        // (large) values land in prev_row[len2].
        BitVec warm_a = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec warm_b = BitVecInit(ALLOCATOR_OF(&alloc));
        for (int i = 0; i < 5; i++) {
        // (large) values land in prev_row[len2].
        BitVec warm_a = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec warm_b = BitVecInit(ALLOCATOR_OF(&alloc));
        for (int i = 0; i < 5; i++) {
            BitVecPush(&warm_a, (i % 2) == 0);
        BitVecDeinit(&warm_b);
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc)); // empty
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        for (int i = 0; i < 5; i++) {
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc)); // empty
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        for (int i = 0; i < 5; i++) {
            BitVecPush(&bv2, true);
        // the empty->4 distance recycles, so the unfilled prev_row[len2] holds a
        // stale large value rather than a coincidental 4.
        BitVec warm_a = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec warm_b = BitVecInit(ALLOCATOR_OF(&alloc));
        for (int i = 0; i < 4; i++) {
        // stale large value rather than a coincidental 4.
        BitVec warm_a = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec warm_b = BitVecInit(ALLOCATOR_OF(&alloc));
        for (int i = 0; i < 4; i++) {
            BitVecPush(&warm_a, (i % 2) == 1);
        BitVecDeinit(&warm_b);
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc)); // empty
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        for (int i = 0; i < 4; i++) {
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc)); // empty
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
        for (int i = 0; i < 4; i++) {
            BitVecPush(&bv2, false);
        WriteFmt("Testing BitVecEditDistance insertion term\n");
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVec bv1 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2 = BitVecInit(ALLOCATOR_OF(&alloc));
    
        BitVecPush(&bv1, true);
        WriteFmt("Testing BitVecJaccardSimilarity rejects bad second operand\n");
    
        BitVec empty = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bad   = {0};
        WriteFmt("Testing BitVecCorrelation with bv1 shorter than bv2 (no OOB)\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecCorrelation with bv2 shorter than bv1 (no OOB)\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecEntropy on an unbalanced (3 ones, 1 zero) vector\n");
    
        BitVec bv     = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;
        WriteFmt("Testing BitVecBestAlignment all-mismatch best offset == 3\n");
    
        BitVec bv1    = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVec bv2    = BitVecInit(ALLOCATOR_OF(&alloc));
        bool   result = true;