
In low-level systems code such as firmware used by Meta hardware platforms, copying bytes within the same buffer must be safe even when the source and destination ranges overlap. Implement a function that performs memmove-style copying on a byte array.
Given a list of integers buffer representing bytes, and integers dst, src, and count, copy count bytes starting at index src to index dst in place. Return the modified buffer.
Unlike a naive forward copy, your implementation must work correctly when the source and destination ranges overlap.
buffer: List[int], dst: int, src: int, count: intcount bytes from src to dstbuffer is in the range 0..255Example 1
buffer = [1, 2, 3, 4, 5, 6], dst = 2, src = 0, count = 4[1, 2, 1, 2, 3, 4]Example 2
buffer = [10, 20, 30, 40, 50], dst = 0, src = 2, count = 3[30, 40, 50, 40, 50]0 <= len(buffer) <= 10^50 <= count <= len(buffer)0 <= src, dst <= len(buffer)src + count <= len(buffer)dst + count <= len(buffer)buffer = [1, 2, 3, 4, 5, 6], dst = 2, src = 0, count = 4Output[1, 2, 1, 2, 3, 4]WhyThe ranges overlap and `dst > src`, so copying backward preserves the original bytes `[1, 2, 3, 4]`.buffer = [10, 20, 30, 40, 50], dst = 0, src = 2, count = 3Output[30, 40, 50, 40, 50]WhyThe source starts after the destination, so a normal forward copy is safe.buffer = [7, 8, 9], dst = 1, src = 1, count = 2Output[7, 8, 9]WhySource and destination are identical, so the buffer remains unchanged.0 <= len(buffer) <= 10^50 <= count <= len(buffer)0 <= src, dst <= len(buffer)src + count <= len(buffer)dst + count <= len(buffer)0 <= buffer[i] <= 255def memmove(buffer, dst, src, count):