Will a monster move away from its target if it is adjacent and is performing a ranged attack?
Yes, monsters move a minimum amount to maximize their attack, so they will move away to lose disadvantage. If it can't lose disadvantage (i.e. is muddled or does not have enough movement points), it will not attempt to do so.