I am comparing two forms of assembling two C files, one with the optimization flag (-O2) and the other without.
My question is:
Why is this in an optimized version of the assembly, the compiler puts the main function after all the helper functions, while helper functions are included in the source code of the assembly. What does this mean in terms of efficiency? Can anyone comment?
Here is the source file C. Thank you!
#include <stdio.h>
#include <string.h>
int validColor( char *str );
int mathProblem( char *str );
int main( void )
{
char myArray[ 6 ][ 3 ][ 20 ];
int i, valid;
for( i = 0; i < 6; i++ )
{
if ( i % 2 == 0 )
{
valid = 0;
while( valid == 0 )
{
printf( "Enter your favorite color : " );
fgets( myArray[ i ][ 0 ], 20, stdin );
if( myArray[ i ][ 0 ][ 0 ] == '\n' )
break;
valid = validColor( myArray [i ][ 0 ] );
}
}
if ( i % 2 == 1 )
{
valid = 0;
while( valid == 0)
{
printf( "The roots of (x - 4)^2 : " );
fgets(myArray[ i ][ 0 ], 20, stdin);
if(myArray[ i ][ 0 ][ 0 ] == '\n')
break;
valid = mathProblem( myArray[ i ][ 0 ] );
}
}
}
return 0;
}
int validColor( char *str )
{
if( strcmp( str, "Black\n" ) == 0 )
return 1;
if( strcmp( str, "Red\n" ) == 0 )
return 1;
if( strcmp( str, "Blue\n" ) == 0 )
return 1;
return 0;
}
int mathProblem( char *str )
{
if ( atoi( str ) == 2 )
return 1;
if ( strcmp( str, "-2\n" ) == 0 )
return 1;
if ( strcmp( str, "+2\n" ) == 0 )
return 1;
return 0;
}
source
share