A small update:
Also randomly program terminates unexpectedly via a __ADI_AGL_CRT_SW_BRANCHRETURN_5816 exit code (at least I see that code near the _lib_prog_term label in the assembly window.
Not true anymore: it was the while (coutner++) { ... } that terminated upond overflow. Sorry for that.
Marco