In Perl_do_openn(), move {in,out}_{raw,crlf} into the !as_raw block.

These 4 variables are only needed there, so by moving them into the block we
save doing unneeded work for the as_raw case (ie sysopen), and as a side
effect make the function a bit clearer.
Perl_do_openn() should call PerlIO_openn() with arg NULL if narg is 0.

If narg is NULL, then PerlIO_openn() doesn't look at args.

(Technically except for PerlIOStdio_open() if f is non-NULL, which doesn't
check narg and assumes that args[0] is valid. That lack of check is probably
a bug. But it doesn't matter in this case, as f is NULL)

This makes it clear that arg isn't needed at this point in Perl_do_openn().

This is a more complete version of the change made by commit dd37d22f759197ae
(March 2002), which just changed the call to pass 0 for narg.
Perl_do_openn() doesn't need to set num_svs and svp.

These variables are no longer used later in the function, so no need to set
them. This permits the declaration of the variable namesv to be moved from
the top of the function into the blocks that use it.
In Perl_do_openn(), move the variable result into the block that uses it.

This also removes a couple of places which would set result = 0 to simulate
"success" for an a later if block. Those paths now don't even reach that
if block.
In Perl_do_openn(), disambiguate the two separate uses of the variable fd.

Rename the first uses of the variable fd to wanted_fd to show that the
variable is not used to pass a value to later in the function.
Extract the setup code of Perl_do_openn() into S_openn_setup().
Extract the cleanup code of Perl_do_openn() into S_openn_cleanup().

A 12 parameter function is extremely ugly (as demonstrated by the need to add
macros for it to perl.h), but it's private, and it will permit the two-headed
public interface of Perl_do_openn() to be simplified.
Split Perl_do_openn() into Perl_do_open_raw() and Perl_do_open6().

Perl_do_open_raw() handles the as_raw part of Perl_do_openn().
Perl_do_open6() handles the !as_raw part of Perl_do_openn().
do_open6() isn't a great name, but I can't see an obvious concise name that
covers 2 arg open, 3 arg open, piped open, implicit fork, and layers.
Change core uses of Perl_do_openn() to Perl_do_open6() or Perl_do_open_raw().

Calls to Perl_do_openn() all have at least 2 unused arguments which clutter
the code and hinder easy understanding. Perl_do_open6() and
Perl_do_open_raw() each only do one job, so don't have the dead arguments.
Simplify the code in Perl_nextargv().

Split the ternary that called Perl_do_open_raw() and Perl_do_open6() based
on PL_inplace into two different if blocks, and merge these with the following
code which is also conditional on PL_inplace.

Remove the warning code from an else block and re-indent it, to make it clear
that it is always called if control reaches the end of the while loop.
In Perl_nextargv(), move variable declarations into the blocks that use them.

This makes it clearer that variables don't hold values between iterations of
the loop, and permits the variable sv to be made const.