It seems LoopIdiomRecognizer pass recognizes one loop inside memSet as memset and replaces it with memset intrinsic, which might then be converted into memset call, resulting in infinite recursion.
There is parameter -fno-builtins to prevent this, BUT when executing opt as "standalone", this parameter cannot be given to it, with default optimizations it executes the LoopIdiomRecognizer, which causes this problem.
So it would seem opt would need either of the following parameters:
-fno-builtins (do all the same things -fno-builtins does when given to clang)
-disable-loop-idiom (disables loop idiom pass, runs all other default passes)