 
 func bnr_atomic_ptr_load(_ target: bnr_atomic_ptr_t, _ order: bnr_atomic_memory_order_t) -> UnsafeRawPointer? {
     var result: UnsafeRawPointer?
-    DarwinAtomics.shared.load(CInt(MemoryLayout<UnsafeRawPointer>.size), target, &result, order)
+    DarwinAtomics.shared.load(MemoryLayout<UnsafeRawPointer>.size, target, &result, order)
     return result
 }
 
 func bnr_atomic_ptr_exchange(_ target: bnr_atomic_ptr_t, _ desired: UnsafeRawPointer?, _ order: bnr_atomic_memory_order_t) -> UnsafeRawPointer? {
     var new = desired
     var old: UnsafeRawPointer?
-    DarwinAtomics.shared.exchange(CInt(MemoryLayout<UnsafeRawPointer>.size), target, &new, &old, order)
+    DarwinAtomics.shared.exchange(MemoryLayout<UnsafeRawPointer>.size, target, &new, &old, order)
     return old
 }
 
 func bnr_atomic_ptr_compare_and_swap(_ target: bnr_atomic_ptr_t, _ expected: UnsafeRawPointer?, _ desired: UnsafeRawPointer?, _ order: bnr_atomic_memory_order_t) -> Bool {
     var expected = expected
     var desired = desired
-    return DarwinAtomics.shared.compareExchange(CInt(MemoryLayout<UnsafeRawPointer>.size), target, &expected, &desired, order, .relaxed) == 1
+    return DarwinAtomics.shared.compareExchange(MemoryLayout<UnsafeRawPointer>.size, target, &expected, &desired, order, .relaxed)
 }
 
 typealias bnr_atomic_flag = Bool

    }
}

private struct DarwinAtomics {
    let load: @convention(c) (CInt, UnsafeMutableRawPointer, UnsafeMutableRawPointer, bnr_atomic_memory_order_t) -> Void
    let exchange: @convention(c) (CInt, UnsafeMutableRawPointer, UnsafeMutableRawPointer, UnsafeMutableRawPointer, bnr_atomic_memory_order_t) -> Void
    let compareExchange: @convention(c) (CInt, UnsafeMutableRawPointer, UnsafeMutableRawPointer, UnsafeMutableRawPointer, bnr_atomic_memory_order_t, bnr_atomic_memory_order_t) -> CInt
    let or8: @convention(c) (UnsafeMutablePointer<UInt8>, UInt8, bnr_atomic_memory_order_t) -> UInt8
    let and8: @convention(c) (UnsafeMutablePointer<UInt8>, UInt8, bnr_atomic_memory_order_t) -> UInt8

    static let shared: DarwinAtomics = {
        let library = UnsafeMutableRawPointer(bitPattern: -2)
        return DarwinAtomics(
            load: library.symbol(named: "__atomic_load"),
            exchange: library.symbol(named: "__atomic_exchange"),
            compareExchange: library.symbol(named: "__atomic_compare_exchange"),
            or8: library.symbol(named: "__atomic_fetch_or_1"),


func bnr_atomic_bitmask_test(_ target: bnr_atomic_bitmask_t, _ mask: UInt8, _ order: bnr_atomic_memory_order_t) -> Bool {
    var result: UInt8 = 0
    DarwinAtomics.shared.load(MemoryLayout<UInt8>.size, target, &result, order)
    return (result & mask) != 0
}
#endif
