Rewriting the reference code from arduin.cc in standalone AVR C