Move memcpy inside if statement