title: CompileError: WebAssembly.compile()
body: <p>I am trying to execute basic C code of calculating factorial in WebAssembly and when I am loading WASM file in Google Chrome ( 57.0.2987.98) I am getting </p>
  
  <blockquote>
    <p>CompileError: WebAssembly.compile():<br>
    Wasm decoding failedResult = expected magic word 00 61 73 6d,<br>
    found 30 30 36 31 @+0`</p>
  </blockquote>
  
  <p>C Code : </p>
  
  <pre><code>double fact(int i) {
    long long n = 1;
    for (;i &gt; 0; i--) {
      n *= i;
    }
    return (double)n;
  }
  </code></pre>
  
  <p>WAST : </p>
  
  <pre><code>(module
    (table 0 anyfunc)
    (memory $0 1)
    (export "memory" (memory $0))
    (export "_Z4facti" (func $_Z4facti))
    (func $_Z4facti (param $0 i32) (result f64)
      (local $1 i64)
      (local $2 i64)
      (block $label$0
        (br_if $label$0
          (i32.lt_s
            (get_local $0)
            (i32.const 1)
          )
        )
        (set_local $1
          (i64.add
            (i64.extend_s/i32
              (get_local $0)
            )
            (i64.const 1)
          )
        )
        (set_local $2
          (i64.const 1)
        )
        (loop $label$1
          (set_local $2
            (i64.mul
              (get_local $2)
              (tee_local $1
                (i64.add
                  (get_local $1)
                  (i64.const -1)
                )
              )
            )
          )
          (br_if $label$1
            (i64.gt_s
              (get_local $1)
              (i64.const 1)
            )
          )
        )
        (return
          (f64.convert_s/i64
            (get_local $2)
          )
        )
      )
      (f64.const 1)
    )
  ) 
  </code></pre>
  
  <p>WASM Compiled Code : </p>
  
  <pre><code>0061 736d 0100 0000 0186 8080 8000 0160
  017f 017c 0382 8080 8000 0100 0484 8080
  8000 0170 0000 0583 8080 8000 0100 0106
  8180 8080 0000 0795 8080 8000 0206 6d65
  6d6f 7279 0200 085f 5a34 6661 6374 6900
  000a c380 8080 0001 bd80 8080 0001 027e
  0240 2000 4101 480d 0020 00ac 4201 7c21
  0142 0121 0203 4020 0220 0142 7f7c 2201
  7e21 0220 0142 0155 0d00 0b20 02b9 0f0b
  4400 0000 0000 00f0 3f0b 
  `
  </code></pre>
  
  <p>Code executed in Chrome : </p>
  
  <pre><code> async function load(){
          let binary = await fetch('https://flinkhub.com/t.wasm');
          let bytes = await binary.arrayBuffer();
          console.log(bytes);
  
          let module = await WebAssembly.compile(bytes);
          let instance = await WebAssembly.Instance(module);
      }
      load().then(instance =&gt; console.log(instance.exports.fact(3)));
  </code></pre>
  
  <p>Can anyone help me out, I have been stuck on this for a whole day and not able to understand what is going wrong.
  I used <a href="https://mbebenita.github.io/WasmExplorer/" rel="noreferrer">WebAssembly Explorer</a> to to get the WAST and WASM code. </p>