title: Convert a float literal to int representation in x86 assembly?
body: <p>The following C code:</p>
  
  <pre class="lang-c prettyprint-override"><code>int main()
  {
      float f;
      f = 3.0;
  }
  </code></pre>
  
  <p>Is converted to the following assembly instructions:</p>
  
  <pre class="lang-x86 prettyprint-override"><code>main:
    pushl %ebp
    movl %esp, %ebp
    subl $16, %esp
    flds .LC0
    fstps -4(%ebp)
    movl $0, %eax
    leave
    ret
  .LC0:
    .long 1077936128
  </code></pre>
  
  <p>What is the correct way to calculate the <code>.long</code>/<code>int</code> representation of the <code>float</code> literal?</p>
  
  <p><em>e.g.</em> <code>1077936128</code> generated from <code>3.0</code> for the example shown above</p>
  
  <hr>
  
  <blockquote>
    <p>For this example <code>gcc</code> is used with the <code>-m32 -S -O0 -fno-stack-protector -fno-asynchronous-unwind-tables</code> flags using intel settings to generate the assembly output.</p>
  </blockquote>
  
  <p><strong>References</strong>:</p>
  
  <p><a href="https://godbolt.org/g/X6mgaT" rel="nofollow noreferrer">Compiler Explorer Link</a>  with compilation flags and other settings</p>