XS.xs 

static int consume_utf8_bytes(U8* in, U8* out) {
    // ...

    for(i = 1; i < bytes; i++) {
        if((in[i] & 0b11000000) != 0b10000000) {
            return(0);
        }
        cp <<= 6;
        cp += in[i] & 0b00111111;
    }

    d = uvchr_to_utf8(out, cp);
    *d = '\0';
    return(bytes);
}