So, when I compile a .c/.cpp file with the -O3 flag, I imagine that it "fixes" a lot of the things that I did "wrong".
My question is, is there a way to make gcc or some other compiler spit out a human readable file that isn't assembly showing me how the code was written?
Like, a 1-to-1 mapping between a normal C/C++ ASCII file and the assembly it produces, assuming no other architecture specific optimizations were used (32 vs 64 bit is okay, I mean something like the -march=native flag).
I'm just curious how super optimized C/C++ would look or what could I have written differently.
Is -fdump-tree-optimized what I'm after here?
For example, this code :
Code:
#include <stdio.h>
#include <stdlib.h>
int main(void) {
const int size = 1000;
int *x = malloc(size * sizeof(*x));
for (int i = 0; i < size; ++i) {
x[i] = i*i;
printf("%d\n", x[i]);
}
free(x);
return 0;
}
compiled with gcc -std=c11 -fdump-tree-optimized -O3 yields this .optimized file :
Code:
;; Function main (main, funcdef_no=8, decl_uid=2122, symbol_order=8) (executed once)
Removing basic block 5
main ()
{
unsigned long ivtmp.4;
int i;
int * x;
int _9;
<bb 2>:
x_5 = malloc (4000);
<bb 3>:
# ivtmp.4_14 = PHI <ivtmp.4_1(3), 0(2)>
i_16 = (int) ivtmp.4_14;
_9 = i_16 * i_16;
MEM[base: x_5, index: ivtmp.4_14, step: 4, offset: 0B] = _9;
printf ("%d\n", _9);
ivtmp.4_1 = ivtmp.4_14 + 1;
if (ivtmp.4_1 != 1000)
goto <bb 3>;
else
goto <bb 4>;
<bb 4>:
free (x_5);
return 0;
}
Now, I don't think this will even compile but go the compiler for the yolo goto's though?