Revert "Cleanup/optimise toposort in write_xaiger"
Revert "Cleanup/optimise toposort in write_xaiger"

This reverts commit 1948e7c846ea318d003148974945d917701a4452.

Restores old toposort with optimisations

SymbiFlow/yosys,cliffordwolf/yosys,YosysHQ/yosys,antmicro/yosys,YosysHQ/yosys,antmicro/yosys,YosysHQ/yosys,YosysHQ/yosys,SymbiFlow/yosys,antmicro/yosys,antmicro/yosys,cliffordwolf/yosys,antmicro/yosys,cliffordwolf/yosys,cliffordwolf/yosys,SymbiFlow/yosys,cliffordwolf/yosys,YosysHQ/yosys,cliffordwolf/yosys,YosysHQ/yosys,cliffordwolf/yosys,SymbiFlow/yosys,antmicro/yosys,antmicro/yosys,cliffordwolf/yosys,antmicro/yosys,YosysHQ/yosys,SymbiFlow/yosys,YosysHQ/yosys,SymbiFlow/yosys,SymbiFlow/yosys,cliffordwolf/yosys,SymbiFlow/yosys