+
+ int source_offset_modulo;
+ int destination_offset_modulo;
+
+ const uint8_t* source = source_origin + byteForBit(source_offset);
+ uint8_t* destination = destination_origin + byteForBit(destination_offset);
+
+ source_offset_modulo = source_offset % CHAR_BIT;
+ destination_offset_modulo = destination_offset % CHAR_BIT;
+
+ if(source_offset_modulo == destination_offset_modulo) {
+ if(source_offset_modulo) {
+ uint8_t c;
+
+ c = reverse_mask_xor[destination_offset_modulo] & *source++;
+
+ PREPARE_FIRST_COPY();
+ *destination++ |= c;
+ }
+
+ int byte_len = source_length / CHAR_BIT;
+ int source_length_modulo = source_length % CHAR_BIT;
+
+ if(byte_len) {
+ memcpy(destination, source, byte_len);
+ source += byte_len;
+ destination += byte_len;
+ }
+ if(source_length_modulo) {
+ *destination &= reverse_mask_xor[source_length_modulo];
+ *destination |= reverse_mask[source_length_modulo] & *source;
+ }
+ } else {
+ int bit_diff_ls;
+ int bit_diff_rs;
+ uint8_t c;
+ /*
+ * Begin: Line things up on destination.
+ */
+ if (source_offset_modulo > destination_offset_modulo) {
+ bit_diff_ls = source_offset_modulo - destination_offset_modulo;
+ bit_diff_rs = CHAR_BIT - bit_diff_ls;
+
+ c = *source++ << bit_diff_ls;
+ c |= *source >> bit_diff_rs;
+ c &= reverse_mask_xor[destination_offset_modulo];
+ } else {
+ bit_diff_rs = destination_offset_modulo - source_offset_modulo;
+ bit_diff_ls = CHAR_BIT - bit_diff_rs;
+
+ c = *source >> bit_diff_rs &
+ reverse_mask_xor[destination_offset_modulo];
+ }
+ PREPARE_FIRST_COPY();
+ *destination++ |= c;
+
+ /*
+ * Middle: copy with only shifting the source.
+ */
+ int byte_len = source_length / CHAR_BIT;
+
+ while(--byte_len >= 0) {
+ c = *source++ << bit_diff_ls;
+ c |= *source >> bit_diff_rs;
+ *destination++ = c;
+ }
+
+ /*
+ * End: copy the remaing bits;
+ */
+ int source_length_modulo = source_length % CHAR_BIT;
+ if(source_length_modulo) {
+ c = *source++ << bit_diff_ls;
+ c |= *source >> bit_diff_rs;
+ c &= reverse_mask[source_length_modulo];
+
+ *destination &= reverse_mask_xor[source_length_modulo];
+ *destination |= c;