//! returns: 0
//! Logical conditions evaluate operands in order and skip unneeded ones.

/// Count an evaluated operand and return its value.
fn probe(count: &mut u32, value: bool) -> bool {
    set *count += 1;
    return value;
}

/// Branch on `a and not (b or c)`.
fn select(a: i32, b: i32, c: i32) -> i32 {
    if a > 0 and not (b == 0 or c < 0) {
        return 1;
    }
    return 0;
}

@default fn main() -> i32 {
    assert select(1, 1, 0) == 1;
    assert select(0, 1, 0) == 0;
    assert select(1, 0, 0) == 0;
    assert select(1, 1, -1) == 0;

    let mut count: u32 = 0;
    if probe(&mut count, false) and probe(&mut count, true) {
        return 1;
    }
    assert count == 1;
    if not (probe(&mut count, true) or probe(&mut count, true)) {
        return 2;
    }
    assert count == 2;
    if probe(&mut count, true) and probe(&mut count, false) {
        return 3;
    }
    assert count == 4;
    while probe(&mut count, true) and count < 6 {}
    assert count == 6;
    return 0;
}
