title: How to get the gcc compiler to not optimize a standard library function call like printf?
body: <p>Out of curiosity, I was wondering if there is any way that gcc does not optimize any function calls?</p>
  
  <p>In the generated assembly code, the printf function is replaced by putchar. This happens even with the default <code>-O0</code> minimal optimization flag.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main(void) {
      printf("a");
      return 0;
  }
  </code></pre>
  
  <p>(<a href="https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(fontScale:1.0749542399999998,j:1,lang:c%2B%2B,source:&#39;%23include+%3Cstdio.h%3E%0A%0Aint+main(void)+%7B%0A++++printf(%22a%22)%3B%0A++++return+0%3B%0A%7D&#39;),l:&#39;5&#39;,n:&#39;0&#39;,o:&#39;C%2B%2B+source+%231&#39;,t:&#39;0&#39;)),k:32.752902155887234,l:&#39;4&#39;,n:&#39;0&#39;,o:&#39;&#39;,s:0,t:&#39;0&#39;),(g:!((h:compiler,i:(compiler:g91,filters:(b:&#39;0&#39;,binary:&#39;1&#39;,commentOnly:&#39;0&#39;,demangle:&#39;0&#39;,directives:&#39;0&#39;,execute:&#39;1&#39;,intel:&#39;0&#39;,libraryCode:&#39;1&#39;,trim:&#39;1&#39;),fontScale:1.0749542399999998,lang:c%2B%2B,libs:!(),options:&#39;-O0+-Wall&#39;,source:1),l:&#39;5&#39;,n:&#39;0&#39;,o:&#39;x86-64+gcc+9.1+(Editor+%231,+Compiler+%231)+C%2B%2B&#39;,t:&#39;0&#39;)),k:33.913764510779444,l:&#39;4&#39;,m:100,n:&#39;0&#39;,o:&#39;&#39;,s:0,t:&#39;0&#39;),(g:!((h:compiler,i:(compiler:clang800,filters:(b:&#39;0&#39;,binary:&#39;1&#39;,commentOnly:&#39;0&#39;,demangle:&#39;0&#39;,directives:&#39;0&#39;,execute:&#39;1&#39;,intel:&#39;0&#39;,libraryCode:&#39;1&#39;,trim:&#39;1&#39;),fontScale:1.0749542399999998,lang:c%2B%2B,libs:!(),options:&#39;-O0+-Wall&#39;,source:1),l:&#39;5&#39;,n:&#39;0&#39;,o:&#39;x86-64+clang+8.0.0+(Editor+%231,+Compiler+%232)+C%2B%2B&#39;,t:&#39;0&#39;)),k:33.33333333333333,l:&#39;4&#39;,n:&#39;0&#39;,o:&#39;&#39;,s:0,t:&#39;0&#39;)),l:&#39;2&#39;,n:&#39;0&#39;,o:&#39;&#39;,t:&#39;0&#39;)),version:4" rel="nofollow noreferrer">Godbolt</a> showing GCC9 doing it, clang8 keeping it unchanged.)</p>