The code is a bit difficult to understand, 
The following string is always unchanged, fixed,
function Main(
...
function
My thoughts are:
Use regular matching to the Main function body, save to the variable b, delete it from _s, and append var b to the after of the _s

The following string is always unchanged, fixed,
function Main(
...
function
My thoughts are:
Use regular matching to the Main function body, save to the variable b, delete it from _s, and append var b to the after of the _s