title: Why did GCC generate mov %eax,%eax and what does it mean?
body: <p>GCC 4.4.3 generated the following x86_64 assembly. The part that confuses me is the <code>mov %eax,%eax</code>. Move the register to itself? Why?</p>
  
  <pre><code>   23b6c:       31 c9                   xor    %ecx,%ecx        ; the 0 value for shift
     23b6e:       80 7f 60 00             cmpb   $0x0,0x60(%rdi)  ; is it shifted?
     23b72:       74 03                   je     23b77
     23b74:       8b 4f 64                mov    0x64(%rdi),%ecx  ; is shifted so load shift value to ecx
     23b77:       48 8b 57 38             mov    0x38(%rdi),%rdx  ; map base
     23b7b:       48 03 57 58             add    0x58(%rdi),%rdx  ; plus offset to value
     23b7f:       8b 02                   mov    (%rdx),%eax      ; load map_used value to eax
     23b81:       89 c0                   mov    %eax,%eax        ; then what the heck is this? promotion from uint32 to 64-bit size_t?
     23b83:       48 d3 e0                shl    %cl,%rax         ; shift rax/eax by cl/ecx
     23b86:       c3                      retq   
  </code></pre>
  
  <p>The C++ code for this function is:</p>
  
  <pre><code>    uint32_t shift = used_is_shifted ? shift_ : 0;
      le_uint32_t le_map_used = *used_p();
      size_t map_used = le_map_used;
      return map_used &lt;&lt; shift;
  </code></pre>
  
  <p>An <code>le_uint32_t</code> is a class which wraps byte-swap operations on big-endian machines. On x86 it does nothing. The <code>used_p()</code> function computes a pointer from the map base + offset and returns a pointer of the correct type.</p>