[Question]
  [
# Introduction
Write a complete program that rotates a rectangular block of ASCII characters 90 degrees clockwise. When the program itself is rotated 90 degrees clockwise, it rotates a block of ASCII characters 90 counterclockwise.
# Rules
* You many not use built-ins that rotate or transpose matrices. For example, in MATLAB/Octave `rot90` and the transpose operator `'` are not allowed.
* You must write a complete program that uses STDIN and STDOUT or the closest equivalent.
* Your program must be rectangular and assume the input is also rectangular.
* The input and output are a newline separated strings and will not have trailing newlines.
When run with its source code as input, your program must rotate itself 90 degrees clockwise. The output must be a second program in the same language that rotates its input 90 degrees counterclockwise. When the rotated program is given its source code as input, it should output the source code of the original program.
**Note:** Both programs must work for *any* input, not just their own source code, so a one character quine is not allowed.
# Example
Say the following is a valid program that rotates its input 90 degrees in a hypothetical language ExampleLang.
```
^f a2% 3
lk (^_^&
       v
D8 $4  /
```
When run with itself as input, it outputs another valid program that rotates its input counterclockwise:
```
D l^
8 kf
    
$ (a
4 ^2
  _%
  ^ 
/v&3
```
This second program, when given to itself as input, outputs the original program. Note that the blank line should have four spaces and there is a trailing space on the second to last line that cannot be rendered in markdown. To clarify:
```
$ examplelang program < program > rotProg
$ examplelang rotProg < rotProg > program1
$ diff -s program program1
Files program and program1 are identical
```
Shortest program wins. Standard loopholes are banned.
  
[Answer]
# CJam, ~~26~~ ~~25~~ 21 bytes
```
WqN/":.+""\%"(~+N-~N*
```
*Thanks to @MartinBüttner for golfing off 4 bytes!*
Try it online in the CJam interpreter: [original program](http://cjam.aditsu.net/#code=WqN%2F%22%3A.%2B%22%22%5C%25%22(~%2BN-~N*&input=ABC%0ADEF%0AGHI) | [rotated program](http://cjam.aditsu.net/#code=W%0Aq%0AN%0A%2F%0A%22%0A%3A%0A.%0A%2B%0A%22%0A%22%0A%5C%0A%25%0A%22%0A(%0A~%0A%2B%0AN%0A-%0A~%0AN%0A*&input=ABC%0ADEF%0AGHI)
This is the rotated program:
```
W
q
N
/
"
:
.
+
"
"
\
%
"
(
~
+
N
-
~
N
*
```
### Idea
We can rotate the input a quarter turn clockwise by splitting it at linefeeds, reversing the order of the resulting rows, transposing rows with columns, and finally joining the rows, separated by linefeeds.
Likewise, we can rotate counterclockwise by transposing first, then reversing the rows.
Since the transposition built-in `z` is forbidden, we can use `:.+` (reduce by vectorized character or string-character concatenation) to achieve the same effect.
`:.+` is the only part of the source code that cannot be broken up. We push the strings `"W%"` and `":.+"`, conditionally reverse them if the second string contains a linefeed, concatenate, remove all linefeeds, and evaluate the result.
### Code
```
W     e# Push -1.
qN/   e# Read all input at split it at linefeeds.
":.+" e# Push a string that, when evaluated, transposes rows and columns.
      e# As explained in the previous section, this does NOT use a built-in
      e# for matrix transposition.
"\%"  e# Push a string that, when evaluated, reverses the rows.
(~    e# Shift out the first character and evaluate it.
      e# For the original code, this evaluates '\', swapping the strings on
      e# the stack. For the rotated code, this evaluates `\n', doing nothing.
+N-   e# Concatenate and remove linefeeds.
      e# The stack now contains:   -1 input "%:.+"   or   -1 input ":.+\%"
~     e# Evaluate the string on top of the stack.
N*    e# Join the resulting array, separating by linefeeds.
```
[Answer]
# [C (gcc)](https://gcc.gnu.org/), ~~1420~~ ~~1399~~ 463 bytes
Ah... the joy of strings of undetermined length!
Assumes `sizeof(char*) == sizeof(int)` and `sizeof(char**) <= 16`.
## The new approach
```
char**L,*r;n,i//j=>]l n}q(( 
,j,q;R(l){for(//,l)l, +;;rr 
r=l=0;(j=     //i=)[r +))oa 
getchar())>10;//,r(r( *l(fh}
r[l++]=j,r[l]=//n(r,c=6=R)c;
0)r=realloc(r,//;rajoL1q()t)
l+2);l&&R((L= //roh=l(,,r"u)
realloc(L,++n*//*fc]l(Lro"p]
16))[n-1]=r,q=//,{t+aR(=f(;q
l);}main(){for//L)e+e&c]{sn[
(R();i<q;i++, //*lglr&o1)t<]
puts(""))for(j//*(=[=ll-(uj+
=n;j--;putchar//rRjrr;lnnp;+
(L[j][i]));}  //a;(;))a[i;0j
////////////////hq;002e)a-=[
////////////////c,01=+r)m-jL
```
[Try it online!](https://tio.run/##7VG7buQwDOz1FcYWC9KSITtFGob5AlduDRWGsA8LjLxmvNVivz2RA6S5@4PDTUXwNeRMbC4xfn3F66R13btaKbvZ@8TvQar8XAEq45JbaQDBx3lR8N4JiqsskWpllIVbgsTVDu9nxlEri7hMlbmctn0zIL53LZVJBYWqFjhfn0ZHsTZwciUI7H0GdZFfecBIpkVlPU0iSyxp70mntPTdCrihEfuCJMfjANBz4dTlygLO6eGO5neqd9bm2vv6HINAr8vhFkz3ijjmpgusbi2c7rHZaQA@A61GkJ4f05zh51HvezzZ0zGGx2ceDQyANL@tNFvrCmctF9Hj0uH2Fsztvn3C4YC4C5RKEXhkkQbuyRrOlJqGSs@uRbl2SKokOd/IGujHFMY5YOHe5ZsICHEaZ2qT8X/gulLbvpxwanj8qxhd27FV/GhS/9/Qf8zQbw "C (gcc) – Try It Online")
[Output of the above](https://tio.run/##7ZGxbuMwDIZ3PYWQISAtGbE7dGHZJ/Dk1fAgCE5igZVj1pmCPHtPvsMNh3uDopyIT/z5/wJjfYnx6@t0Ar6BtCqNXtRHczp1@d7j6@RwmDhdCxhoA8LworKJDwWk9IlPFGQXedUCxhroYxBSd22o2iX1YQ55kWkM1O9gpsPbXMdjYAXodskN19zCURIk8QXgHQnGrhePjLsEt/OM7GFRtI/dheLiHuogDu/2TAU8r@rO3nUlv11yATaAX9bMOjZW96VWk1WurGeyMBfwb/0P4jVoVXW@Usp@9sn4lXoQfJwXBWVh0xAkvkzbPgmI76ZtSAdxbuTkSzMablBZpyCyRFAvxr0gyfHYl5@zLWX@Pna@fa2cywZxyHU7svqVBelpPsKc4Y9rD0irqWu63bdPOBwQd2oSN5Te8k5/RzHdkEqIYR2xLCguP8f9xsf9BQ "C (gcc) – Try It Online")
The solution was embarrassingly easy in the end. You make one program A that rotates things clockwise, and one program B that rotates counter-clockwise:
### A
```
char**L,*r;n,i,j,q;R(l){for(r=l=0;(j=getchar())>10;r[l++]=j,r[l]=0)r=realloc(r,l+2);l&&R((L=realloc(L,16*++n))[n-1]=r,q=l);}main(){for(R();i<q;i++,puts(""))for(j=n;j--;)putchar(L[j][i]);}
```
### B
```
char**L,*r;n,i,j,q;R(l){for(r=l=0;(j=getchar())>10;r[l++]=j,r[l]=0)r=realloc(r,l+2);l&&R((L=realloc(L,16*++n))[n-1]=r,q=l);}main(){for(R();q--;puts(""))for(j=0;j<n;j++)putchar(L[j][q]);}
```
Make a rectangle of reasonable proportions and confine A to that, and put guards of comments around it:
```
char**L,*r;n,i//
,j,q;R(l){for(//
r=l=0;(j=     //
getchar())>10;//
r[l++]=j,r[l]=//
0)r=realloc(r,//
l+2);l&&R((L= //
realloc(L,++n*//
16))[n-1]=r,q=//
l);}main(){for//
(R();i<q;i++, //
puts(""))for(j//
=n;j--;putchar//
(L[j][i]));}  //
////////////////
////////////////
```
Confine program B to a square that is the same width as the one for A plus two (for the extra lines of comments at the bottom edge), rotate it CCW and slap it to the right of program A and you get the solution above.
## The old approach
```
 /*                                       r                               c                                                         c                                                  r               
r                                         a                               o                         n                               o                          s                       a               
a                          r              h                               l                         i       r                       l             r      -     t        r  =    +      h         q     
h                          o              c        0     +                l                         a       o             +         l       6     o      -     u    "   o  j<   +      c  */           
char**L,*s,*r;n,i,q;R(l,c){for(r=l=0;(c=getchar())>10;r[l++]=c,r[l]=0)r=realloc(r,l+2);q=l?l:q;l=r;}main(j){for(;s=R();L[n++]=s)L=realloc(L,16*n);for(;i<q;i++,puts(""))for(j=n;j--;)putchar(L[j][i]);}
 ///                        //          //e////     /     /             //e////                      ///     //            /      //e////    /     //  //  //// ///  /   // ;/   /// //u////      /    
 ///                        //          //g////     /     /             //r////                      ///     //            /      //r////    /     //  //  //// ///  /   // 0/   /// //p////      /    
```
[Try it online!](https://tio.run/##7VQ9b4MwEN3zK1AmfyGTDhl6cfsHmLIiBmSlCciFcCRTld@e8tEGKyHCZeiEJc7o3r3ne7Z02t9rfb16knluC0dw7U1dE5j3zSzQmZqM4MVTJJ/M9CrHZhaJs@fDSDfmKZKOvKgZOtZv48nKqmbn982UnY@D8zXdXj/wLEEXH8mgIH9gru2qzse5Ccsum216Vt0Mk/Z76EOCjIWCVYIh5CIVJWyJEZp@fRRIUBkVANFqvzs1pYTSt1UAGBnOY6VF/ROrgKLCXWJMoQkKw18olMq8m9cSjEK4fCZpTrJOECq1JRTCKG8EKhremKFYrVlOoa1KNyWknIvj@VSR5ZLSJpupHDLfB1pn22bCKIujNKZwWXhSymf3aCNS7uRvqR2H8AEh@SB4E7CYfVX31bFFZJcF@aMl5bk/rN3@4GM/4gMn@0BHH0Hv43jnYx688@CdB@88eOfB@8@D9xs "C (gcc) – Try It Online")
[Output of the above](https://tio.run/##7ZW9boMwEMd3nsLKBCHIpEOGEtoXYOoaMSCL8iECCZCp6rOnJj6X9C8spVVHTz/ufNj3ZZ8ICiGuV8ZEmfXM4bxkjHHJTHIt2UsyR34DE@IG9INBr/eJiC3YVSCfwf6N6BIbsBdEj/hBfO/kyTKO7ibP8bjgVwz7ajkEP1w4L6Z9C2J@Y5GPU0KlLEhfEjODHx7whbgNlT36of8/gN@@r@x9klOIR0DeTPukhjx4i3nT8ej4@zxrmk5IuSG9pq6DMNRhg/EQn@D8CPoE6/cK8rOhr7De2KefxGNWtff1q4gtxFH/sQ8juD@xoe8x/gTq1z7YBwPsl/xzPfF92O6U3Q7ehdYQ12P5muuw1/UNgsV1H6j9Ol3GYZIvpB@JA5y3Win9ynBfjf7WMqNOGNV7pY8hbh1vPRVMrgf0v2b04xzOT0Tlr/Te9M6syQ@@XJcD9Gv6rT/f5W3We4v3wk4OOzns5LCTw04OOzl@Nzm@AA "C (gcc) – Try It Online")
[Answer]
# [Python 3](https://docs.python.org/3/), 119 bytes
```
[print(*i[# "i  0: 
::-1],sep#t " **(: 
="")for i#n,=r[(n[]
in zip(* #iiponpe]]
open(0))]#r*efiip)1
#########[p(s) zo)-
```
[Try it online!](https://tio.run/##Ncg7DsMgDADQnVNYsGCUSKHphJShn1sghn6I6sVYhKW5PM3SNz75tk/hufcolbhZR9GAJoApgAph9GnYspgGGpyzxy1a41oqkOFhqdFyTIoYdhLrwBBJYckpqSKZ7YSYTHV5PR69Mn9R7IawFxx7v1xvd@VP81k9nq/3Dw "Python 3 – Try It Online")
rotated :
```
#oi=:[
#pn":p
#e "-r
#nz)1i
#(if]n
#0po,t
#)(rs(
#)* e*
#] ipi
[####[
print#
(*i,  
sep=""
)for i
 in[* 
zip(* 
open(0
))][::
-1]]  
```
[Try it online!](https://tio.run/##DcU5DsMgEAXQ/p9ixDSAbMmOUyG5yHILRJGFKNPACLuJL@/4NU9/67eWad@5yhwiWIsJCs5k@gYumxsFbOWTCnjQ2q1gZ9tijzxlD04kKoh8iNAmZWVYLx0RlqyzMXCf2khAUqInbKL2qGoudoBzKYaAfkyJaN8f4wXP0xWv6Yb3@f4H "Python 3 – Try It Online")
## How it works :
The code is coposed of 2 parts separed by comments :
```
1111111111#22222222
111111111#222222222
111111111#222222222
111111111#222222222
111111111#222222222
#########2222222222
```
The first code rotates cockwise :
```
[print(*i[::-1],sep="")for i in zip(*open(0))]
```
[Try it online!](https://tio.run/##K6gsycjPM/7/P7qgKDOvREMrM9rKStcwVqc4tcBWSUkzLb9IIVMhM0@hKrNAQyu/IDVPw0BTM/b/f0cnZxcuQyNjE67EpOQUAA "Python 3 – Try It Online")
The second rotates counter clockwise
```
[print(*i,sep="")for i in[*zip(*open(0))][::-1]]
```
[Try it online!](https://tio.run/##K6gsycjPM/7/P7qgKDOvREMrU6c4tcBWSUkzLb9IIVMhMy9aqyqzQEMrvyA1T8NAUzM22spK1zA29v//RENHriQjJ65kY2euFBMXAA "Python 3 – Try It Online")
]