//! returns: 0
//! Test returning a slice from a function and iterating over it.
//! Exercises the same code path as createBlock's vars initialization.
//! The slice is returned through a return buffer (> 8 bytes).

unsafe fn makeSlice(buf: *unsafe mut [u8], count: u32) -> *unsafe mut [u8] {
    if count == 0 {
        return &mut [];
    }
    return @sliceOf(&mut buf[0], count);
}

unsafe fn initSlice(buf: *unsafe mut [u8], count: u32) -> i32 {
    let s = makeSlice(buf, count);

    // This loop pattern matches createBlock's vars initialization.
    for i in 0..s.len {
        set s[i] = 0;
    }

    return s.len as i32;
}

@default unsafe fn main() -> i32 {
    let mut buf: [u8; 64] = undefined;

    let n = initSlice(&mut buf[..], 5);
    assert n == 5;

    let n2 = initSlice(&mut buf[..], 0);
    assert n2 == 0;

    return 0;
}
