// Test bitwise VM builtins

fn main() {
    // Basic AND/OR/XOR
    println("bit_and(0xFF, 0x0F) = " + int_to_str(bit_and(255, 15)))
    println("bit_or(0xF0, 0x0F) = " + int_to_str(bit_or(240, 15)))
    println("bit_xor(0xFF, 0x0F) = " + int_to_str(bit_xor(255, 15)))

    // Shifts
    println("shl(1, 16) = " + int_to_str(shl(1, 16)))
    println("shr(65536, 16) = " + int_to_str(shr(65536, 16)))

    // Montgomery-relevant: mask low 16 bits
    let x = 207093761
    let low16 = bit_and(x, 65535)
    println("207093761 & 0xFFFF = " + int_to_str(low16))

    // Kyber constants verification
    let q = 3329
    let qinv = 62209
    let product = q * qinv
    let mod_r = bit_and(product, 65535)
    println("3329 * 62209 mod 2^16 = " + int_to_str(mod_r) + " (should be 1)")

    // bit_not
    println("bit_not(0) = " + int_to_str(bit_not(0)))

    println("All bitwise builtins working!")
}
