Add option to output result in GAP format.
Check malloc results for success.