title: How can I prove or disprove the efficiency of compilation?
body: <p>This is an unusual question, but I do hope there's a definitive answer.</p>
  
  <p>There's a longstanding debate in our office about how efficiently compilers generate code, specifically number of instructions. We write code for low power embedded systems with virtually no loops. Therefore, the number of instructions emitted is directly proportional to power consumed.</p>
  
  <p>Much of our code looks like this (notice, no dynamic memory allocation, no system calls, very few function calls, very few loops).</p>
  
  <pre><code>foo += 3 * (77 + bar);
  if (baz &gt; 18 - qux)
      bar -= 19 + 7 &gt;&gt; spam;
  </code></pre>
  
  <p>I can compile the above snippet with <code>-O3</code> and read the assembly, but I couldn't write it myself.</p>
  
  <p>The claim I would like to prove or disprove is that compilers generate code that is 2-4X "fatter" (and therefore consume 2-4X times as much power) compared with hand written assembly code.</p>
  
  <p>I'm interested in any compiler with which you have experience.</p>
  
  <p>From <a href="https://stackoverflow.com/questions/840321/how-can-i-see-the-assembly-code-for-a-c-program">this answer</a> I know that GCC and clang can emit assembly interleaved with the C code with</p>
  
  <pre><code>gcc -g -c -Wa,-alh foo.cc
  </code></pre>
  
  <p>These answers provide solid basis:</p>
  
  <p><a href="https://stackoverflow.com/questions/577554/when-is-assembler-faster-than-c?rq=1">When is assembly faster?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/791533/why-do-you-program-in-assembly?lq=1">Why do you program in assembly?</a></p>
  
  <p>How can I measure the efficiency with which a compiler generates code?</p>