title: Why doesn't GCC optimize this call to printf?
body: <pre><code>#include &lt;stdio.h&gt;
  int main(void) { 
      int i;
      scanf("%d", &amp;i);
      if(i != 30) { return(0); } 
      printf("i is equal to %d\n", i);
  }
  </code></pre>
  
  <p>It appears that the resulting string will always be "i is equal to 30", so, why doesn't GCC optimize this call to printf with a call to <code>puts()</code>, or <code>write()</code>, for example?</p>
  
  <p>(Just checked the generated assembly, with <code>gcc -O3</code> (version 5.3.1), or on the <a href="http://gcc.godbolt.org/#compilers:!((compiler:g530,options:&#39;-xc+-std%3Dgnu11+-Wall+-fverbose-asm++-O3+-march%3Dhaswell+-mavx&#39;,source:&#39;%23include+%3Cstdio.h%3E%0Aint+main(void)+%7B+%0A++++int+i%3B%0A++++scanf(%22%25d%22,+%26i)%3B%0A++++if(i+!!%3D+30)+%7B+return(0)%3B+%7D+%0A++++printf(%22i+is+equal+to+%25d%5Cn%22,+i)%3B%0A%7D&#39;)),filterAsm:(commentOnly:!t,directives:!t,intel:!t,labels:!t),version:3" rel="noreferrer">Godbolt Compiler Explorer</a>)</p>