//! returns: 0
//! Regression test for the global callee-class limit bug.
//!
//! Creates 12 callee-class values where no single call site exceeds
//! 11 crossing values (so per-call-site spilling doesn't trigger), but
//! 12 callee-class values are simultaneously live during register
//! assignment, exceeding the 11 available callee-saved registers.
//!
//! The trick: at call N (backward walk), {v0..v(N-1)} cross; at the last
//! call, v0 is consumed as an argument so only {v1..v11} cross = 11.
//! Each call site has <= 11 crossing values, but callee-class union =
//! {v0..v10} | {v1..v11} = {v0..v11} = 12. Without the global
//! callee-class limit, v11 silently gets a caller-saved register and
//! is clobbered by the subsequent call.

fn id(x: i32) -> i32 {
    return x;
}

fn consume(x: i32) -> i32 {
    return x + 1;
}

@default fn main() -> i32 {
    let v0: i32 = id(1);
    let v1: i32 = id(2);
    let v2: i32 = id(3);
    let v3: i32 = id(4);
    let v4: i32 = id(5);
    let v5: i32 = id(6);
    let v6: i32 = id(7);
    let v7: i32 = id(8);
    let v8: i32 = id(9);
    let v9: i32 = id(10);
    let v10: i32 = id(11);
    let v11: i32 = id(12);

    // v0's last use - consume it via a call.
    // At this call: {v1..v11} cross = 11, exactly fitting numCalleeSaved.
    let v12: i32 = consume(v0);

    let total: i32 = v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8 + v9 + v10 + v11 + v12;
    // v1..v10 = 2+3+...+11 = 65, v11 = 12, v12 = consume(1) = 2
    // total = 65 + 12 + 2 = 79
    assert total == 79;
    return 0;
}
