This still doesn't work. The version here seems to pass make check in that it creates crams and decodes them, but they are not interoperable with crams on other systems due to no byte swapping being used.

It starts with the assumption that the auxiliary data is encoded in the file endianness, not cpu/memory endianness.  I'll look into how best to do this. It seems it will need on-the-fly byte swapping for aux data in cram_encode and cram_decode. This shouldn't be too hard to implement.

I have been playing with a variant of this pull request in my own branch:

https://github.com/jkbonfield/htslib/tree/SPARC

The main change here is ua_read/write functions in hts.h for performing memory accesses that may access unaligned memory. (Arguably we can avoid these completely for CIGAR strings by nul padding the name by 1, 2, 3 or 4 nuls instead of just 1 to ensure the cigar is word aligned again - I doubt it would break anything.)