Index: lib/CodeGen/AsmPrinter/DbgValueHistoryCalculator.cpp
===================================================================
--- lib/CodeGen/AsmPrinter/DbgValueHistoryCalculator.cpp
+++ lib/CodeGen/AsmPrinter/DbgValueHistoryCalculator.cpp
@@ -31,7 +31,7 @@
   assert(MI.isDebugValue());
   assert(MI.getNumOperands() == 4);
   // If location of variable is described using a register (directly or
-  // indirecltly), this register is always a first operand.
+  // indirectly), this register is always a first operand.
   return MI.getOperand(0).isReg() ? MI.getOperand(0).getReg() : 0;
 }
 
@@ -164,7 +164,8 @@
       // Look for register defs and register masks. Register masks are
       // typically on calls and they clobber everything not in the mask.
       for (const MachineOperand &MO : MI.operands()) {
-        if (MO.isReg() && MO.isDef() && MO.getReg()) {
+        if (MO.isReg() && MO.isDef() && MO.getReg() &&
+            !TRI->isVirtualRegister(MO.getReg())) {
           for (MCRegAliasIterator AI(MO.getReg(), TRI, true); AI.isValid();
                ++AI)
             Regs.set(*AI);
@@ -191,7 +192,8 @@
         // Not a DBG_VALUE instruction. It may clobber registers which describe
         // some variables.
         for (const MachineOperand &MO : MI.operands()) {
-          if (MO.isReg() && MO.isDef() && MO.getReg()) {
+          if (MO.isReg() && MO.isDef() && MO.getReg() &&
+              !TRI->isVirtualRegister(MO.getReg())) {
             // If this is a register def operand, it may end a debug value
             // range.
             for (MCRegAliasIterator AI(MO.getReg(), TRI, true); AI.isValid();
@@ -238,7 +240,8 @@
     if (!MBB.empty() && &MBB != &MF->back()) {
       for (auto I = RegVars.begin(), E = RegVars.end(); I != E;) {
         auto CurElem = I++; // CurElem can be erased below.
-        if (ChangingRegs.test(CurElem->first))
+        if (!TRI->isVirtualRegister(CurElem->first) &&
+            ChangingRegs.test(CurElem->first))
           clobberRegisterUses(RegVars, CurElem, Result, MBB.back());
       }
     }
Index: lib/Target/WebAssembly/WebAssemblyRegStackify.cpp
===================================================================
--- lib/Target/WebAssembly/WebAssemblyRegStackify.cpp
+++ lib/Target/WebAssembly/WebAssemblyRegStackify.cpp
@@ -258,6 +258,8 @@
       LIS.getInstructionIndex(*Def).getRegSlot());
   assert(DefVNI);
   for (auto I : MRI.use_nodbg_operands(Reg)) {
+    if (I.getParent()->isDebugValue())
+      continue;
     const auto &Result = LI.Query(LIS.getInstructionIndex(*I.getParent()));
     if (Result.valueIn() == DefVNI) {
       if (!Result.isKill())
@@ -305,7 +307,7 @@
 
     // Ask LiveIntervals whether moving this virtual register use or def to
     // Insert will change which value numbers are seen.
-    // 
+    //
     // If the operand is a use of a register that is also defined in the same
     // instruction, test that the newly defined value reaches the insert point,
     // since the operand will be moving along with the def.
@@ -367,7 +369,10 @@
       continue;
 
     const MachineInstr *UseInst = Use.getParent();
-    VNInfo *UseVNI = LI.getVNInfoBefore(LIS.getInstructionIndex(*UseInst));
+    if (UseInst->isDebugValue())
+      continue;
+    SlotIndex Idx = LIS.getInstructionIndex(*UseInst);
+    VNInfo *UseVNI = LI.getVNInfoBefore(Idx);
 
     if (UseVNI != OneUseVNI)
       continue;
@@ -386,7 +391,7 @@
         //
         // This is needed as a consequence of using implicit get_locals for
         // uses and implicit set_locals for defs.
-        if (UseInst->getDesc().getNumDefs() == 0) 
+        if (UseInst->getDesc().getNumDefs() == 0)
           return false;
         const MachineOperand &MO = UseInst->getOperand(0);
         if (!MO.isReg())
Index: lib/Target/WebAssembly/WebAssemblyReplacePhysRegs.cpp
===================================================================
--- lib/Target/WebAssembly/WebAssemblyReplacePhysRegs.cpp
+++ lib/Target/WebAssembly/WebAssemblyReplacePhysRegs.cpp
@@ -88,6 +88,8 @@
         if (VReg == WebAssembly::NoRegister)
           VReg = MRI.createVirtualRegister(RC);
         MO.setReg(VReg);
+        if (MO.getParent()->isDebugValue())
+          MO.setIsDebug();
         Changed = true;
       }
     }
Index: lib/Target/WebAssembly/WebAssemblyStoreResults.cpp
===================================================================
--- lib/Target/WebAssembly/WebAssemblyStoreResults.cpp
+++ lib/Target/WebAssembly/WebAssemblyStoreResults.cpp
@@ -99,7 +99,11 @@
       continue;
 
     // If this use gets a different value, skip it.
-    SlotIndex WhereIdx = LIS.getInstructionIndex(*Where);
+    SlotIndex WhereIdx;
+    if (Where->isDebugValue())
+      WhereIdx = LIS.getSlotIndexes()->getIndexBefore(*Where);
+    else
+      WhereIdx = LIS.getInstructionIndex(*Where);
     VNInfo *WhereVNI = FromLI->getVNInfoAt(WhereIdx);
     if (WhereVNI && WhereVNI != FromVNI)
       continue;
@@ -118,7 +122,8 @@
     if (!O.isUndef()) {
       MI.getOperand(0).setIsDead(false);
 
-      Indices.push_back(WhereIdx.getRegSlot());
+      if (!Where->isDebugValue())
+        Indices.push_back(WhereIdx.getRegSlot());
     }
   }
 
Index: test/DebugInfo/WebAssembly/live-intervals.ll
===================================================================
--- /dev/null
+++ test/DebugInfo/WebAssembly/live-intervals.ll
@@ -0,0 +1,70 @@
+; RUN: llc < %s -verify-machineinstrs -mtriple=wasm32-unknown-unknown | FileCheck %s
+; CHECK: #DEBUG_VALUE: decode:i <- [%vreg25+12]
+; CHECK: #DEBUG_VALUE: decode:v <- [%vreg25+11]
+; CHECK: DW_TAG_variable
+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
+target triple = "wasm32-unknown-unknown"
+
+%0 = type opaque
+
+@key = external global [15 x i8], align 1
+
+; Function Attrs: nounwind
+define internal zeroext i8 @0(i32, i8 zeroext)  !dbg !14 !type !19 {
+  %3 = alloca i32, align 4
+  %4 = alloca i8, align 1
+  store i32 %0, i32* %3, align 4
+  call void @llvm.dbg.declare(metadata i32* %3, metadata !20, metadata !21), !dbg !22
+  store i8 %1, i8* %4, align 1
+  call void @llvm.dbg.declare(metadata i8* %4, metadata !23, metadata !21), !dbg !24
+  %5 = load i8, i8* %4, align 1, !dbg !25
+  %6 = zext i8 %5 to i32, !dbg !25
+  %7 = load i32, i32* %3, align 4, !dbg !26
+  %8 = urem i32 %7, 15, !dbg !27
+  %9 = getelementptr inbounds [15 x i8], [15 x i8]* @key, i32 0, i32 %8, !dbg !28
+  %10 = load i8, i8* %9, align 1, !dbg !28
+  %11 = zext i8 %10 to i32, !dbg !28
+  %12 = xor i32 %6, %11, !dbg !29
+  %13 = trunc i32 %12 to i8, !dbg !30
+  ret i8 %13, !dbg !31
+}
+
+; Function Attrs: nounwind readnone
+declare void @llvm.dbg.declare(metadata, metadata, metadata)
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!11, !12}
+!llvm.ident = !{!13}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.9.0 (trunk 273884) (llvm/trunk 273897)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, globals: !3)
+!1 = !DIFile(filename: "crash.c", directory: "wasm/tests")
+!2 = !{}
+!3 = !{!4}
+!4 = distinct !DIGlobalVariable(name: "key", scope: !0, file: !1, line: 7, type: !5, isLocal: false, isDefinition: true, variable: [15 x i8]* @key)
+!5 = !DICompositeType(tag: DW_TAG_array_type, baseType: !6, size: 120, align: 8, elements: !9)
+!6 = !DIDerivedType(tag: DW_TAG_typedef, name: "uint8_t", file: !7, line: 185, baseType: !8)
+!7 = !DIFile(filename: "wasm/emscripten/system/include/libc/bits/alltypes.h", directory: "wasm/tests")
+!8 = !DIBasicType(name: "unsigned char", size: 8, align: 8, encoding: DW_ATE_unsigned_char)
+!9 = !{!10}
+!10 = !DISubrange(count: 15)
+!11 = !{i32 2, !"Dwarf Version", i32 4}
+!12 = !{i32 2, !"Debug Info Version", i32 3}
+!13 = !{!"clang version 3.9.0 (trunk 273884) (llvm/trunk 273897)"}
+!14 = distinct !DISubprogram(name: "decode", scope: !1, file: !1, line: 11, type: !15, isLocal: false, isDefinition: true, scopeLine: 11, flags: DIFlagPrototyped, isOptimized: false, unit: !0, variables: !2)
+!15 = !DISubroutineType(types: !16)
+!16 = !{!6, !17, !6}
+!17 = !DIDerivedType(tag: DW_TAG_typedef, name: "size_t", file: !7, line: 124, baseType: !18)
+!18 = !DIBasicType(name: "long unsigned int", size: 32, align: 32, encoding: DW_ATE_unsigned)
+!19 = !{i64 0, !"_ZTSFhmhE"}
+!20 = !DILocalVariable(name: "i", arg: 1, scope: !14, file: !1, line: 11, type: !17)
+!21 = !DIExpression()
+!22 = !DILocation(line: 11, column: 23, scope: !14)
+!23 = !DILocalVariable(name: "v", arg: 2, scope: !14, file: !1, line: 11, type: !6)
+!24 = !DILocation(line: 11, column: 34, scope: !14)
+!25 = !DILocation(line: 12, column: 11, scope: !14)
+!26 = !DILocation(line: 12, column: 19, scope: !14)
+!27 = !DILocation(line: 12, column: 21, scope: !14)
+!28 = !DILocation(line: 12, column: 15, scope: !14)
+!29 = !DILocation(line: 12, column: 13, scope: !14)
+!30 = !DILocation(line: 12, column: 10, scope: !14)
+!31 = !DILocation(line: 12, column: 3, scope: !14)
Index: test/DebugInfo/WebAssembly/variable.ll
===================================================================
--- /dev/null
+++ test/DebugInfo/WebAssembly/variable.ll
@@ -0,0 +1,55 @@
+; RUN: llc < %s -verify-machineinstrs -mtriple=wasm32-unknown-unknown | FileCheck %s
+; CHECK: #DEBUG_VALUE: usage:self <- %vreg0
+; CHECK: DW_TAG_variable
+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
+target triple = "wasm32-unknown-unknown"
+
+%0 = type opaque
+
+@key = external local_unnamed_addr global [15 x i8], align 1
+@.str = external unnamed_addr constant [33 x i8], align 1
+
+; Function Attrs: nounwind
+define internal i32 @0(i8*) local_unnamed_addr !dbg !14 !type !22 {
+  tail call void @llvm.dbg.value(metadata i8* %0, i64 0, metadata !21, metadata !23), !dbg !24
+  %2 = tail call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i32 0, i32 0), i8* %0), !dbg !25
+  ret i32 1, !dbg !26
+}
+
+; Function Attrs: nounwind
+declare i32 @printf(i8* nocapture readonly, ...) local_unnamed_addr
+
+; Function Attrs: nounwind readnone
+declare void @llvm.dbg.value(metadata, i64, metadata, metadata)
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!11, !12}
+!llvm.ident = !{!13}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.9.0 (trunk 273884) (llvm/trunk 273897)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, globals: !3)
+!1 = !DIFile(filename: "crash.c", directory: "wasm/tests")
+!2 = !{}
+!3 = !{!4}
+!4 = distinct !DIGlobalVariable(name: "key", scope: !0, file: !1, line: 7, type: !5, isLocal: false, isDefinition: true, variable: [15 x i8]* @key)
+!5 = !DICompositeType(tag: DW_TAG_array_type, baseType: !6, size: 120, align: 8, elements: !9)
+!6 = !DIDerivedType(tag: DW_TAG_typedef, name: "uint8_t", file: !7, line: 185, baseType: !8)
+!7 = !DIFile(filename: "wasm/emscripten/system/include/libc/bits/alltypes.h", directory: "wasm/tests")
+!8 = !DIBasicType(name: "unsigned char", size: 8, align: 8, encoding: DW_ATE_unsigned_char)
+!9 = !{!10}
+!10 = !DISubrange(count: 15)
+!11 = !{i32 2, !"Dwarf Version", i32 4}
+!12 = !{i32 2, !"Debug Info Version", i32 3}
+!13 = !{!"clang version 3.9.0 (trunk 273884) (llvm/trunk 273897)"}
+!14 = distinct !DISubprogram(name: "usage", scope: !1, file: !1, line: 15, type: !15, isLocal: false, isDefinition: true, scopeLine: 15, flags: DIFlagPrototyped, isOptimized: true, unit: !0, variables: !20)
+!15 = !DISubroutineType(types: !16)
+!16 = !{!17, !18}
+!17 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
+!18 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !19, size: 32, align: 32)
+!19 = !DIBasicType(name: "char", size: 8, align: 8, encoding: DW_ATE_signed_char)
+!20 = !{!21}
+!21 = !DILocalVariable(name: "self", arg: 1, scope: !14, file: !1, line: 15, type: !18)
+!22 = !{i64 0, !"_ZTSFiPcE"}
+!23 = !DIExpression()
+!24 = !DILocation(line: 15, column: 17, scope: !14)
+!25 = !DILocation(line: 16, column: 3, scope: !14)
+!26 = !DILocation(line: 17, column: 3, scope: !14)
Index: test/DebugInfo/WebAssembly/wasm-reg-stackify.ll
===================================================================
--- /dev/null
+++ test/DebugInfo/WebAssembly/wasm-reg-stackify.ll
@@ -0,0 +1,345 @@
+; RUN: llc < %s -verify-machineinstrs -mtriple=wasm32-unknown-unknown | FileCheck %s
+; CHECK: #DEBUG_VALUE: main:argv <- %vreg175
+; CHECK: #DEBUG_VALUE: main:argc <- %vreg11
+; CHECK: #DEBUG_VALUE: main:c <- %vreg175
+; CHECK: #DEBUG_VALUE: main:op <- %vreg175
+; CHECK: #DEBUG_VALUE: main:ip <- %vreg175
+; CHECK: #DEBUG_VALUE: main:buf_size <- %vreg175
+; CHECK: #DEBUG_VALUE: main:buf <- %vreg175
+; CHECK: #DEBUG_VALUE: main:pos <- %vreg175
+; CHECK: __stack_pointer
+; CHECK: DW_TAG_variable
+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
+target triple = "wasm32-unknown-unknown"
+
+%0 = type opaque
+
+@key = external local_unnamed_addr global [15 x i8], align 1
+@.str = external unnamed_addr constant [33 x i8], align 1
+@.str.1 = external unnamed_addr constant [2 x i8], align 1
+@optind = external local_unnamed_addr global i32, align 4
+@.str.2 = external unnamed_addr constant [3 x i8], align 1
+@.str.3 = external unnamed_addr constant [24 x i8], align 1
+@.str.4 = external unnamed_addr constant [50 x i8], align 1
+@.str.5 = external unnamed_addr constant [31 x i8], align 1
+@str = external unnamed_addr constant [36 x i8]
+
+; Function Attrs: nounwind readonly
+declare zeroext i8 @decode(i32, i8 zeroext) local_unnamed_addr
+
+; Function Attrs: nounwind
+declare i32 @usage(i8*) local_unnamed_addr
+
+; Function Attrs: nounwind
+declare i32 @printf(i8* nocapture readonly, ...) local_unnamed_addr
+
+; Function Attrs: nounwind
+define hidden i32 @main(i32, i8**) local_unnamed_addr !dbg !14 !type !36 {
+  tail call void @llvm.dbg.value(metadata i32 %0, i64 0, metadata !22, metadata !37), !dbg !38
+  tail call void @llvm.dbg.value(metadata i8** %1, i64 0, metadata !23, metadata !37), !dbg !39
+  tail call void @llvm.dbg.value(metadata %0* null, i64 0, metadata !24, metadata !37), !dbg !40
+  tail call void @llvm.dbg.value(metadata %0* null, i64 0, metadata !28, metadata !37), !dbg !41
+  %3 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i32 0, i32 0)) , !dbg !42
+  tail call void @llvm.dbg.value(metadata i32 %3, i64 0, metadata !29, metadata !37), !dbg !44
+  switch i32 %3, label %71 [
+    i32 -1, label %7
+    i32 104, label %4
+    i32 63, label %4
+  ], !dbg !45
+
+; <label>:4:                                      ; preds = %2, %2
+  %5 = load i8*, i8** %1, align 4, !dbg !46, !tbaa !49
+  %6 = tail call i32 @usage(i8* %5), !dbg !53
+  br label %71, !dbg !54
+
+; <label>:7:                                      ; preds = %2
+  %8 = load i32, i32* @optind, align 4, !dbg !55, !tbaa !57
+  %9 = add nsw i32 %8, 2, !dbg !59
+  %10 = icmp slt i32 %9, %0, !dbg !60
+  br i1 %10, label %11, label %34, !dbg !61
+
+; <label>:11:                                     ; preds = %7
+  %12 = getelementptr inbounds i8*, i8** %1, i32 %8, !dbg !62
+  %13 = load i8*, i8** %12, align 4, !dbg !62, !tbaa !49
+  %14 = tail call %0* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i32 0, i32 0)), !dbg !65
+  tail call void @llvm.dbg.value(metadata %0* %14, i64 0, metadata !24, metadata !37), !dbg !40
+  %15 = icmp eq %0* %14, null, !dbg !66
+  %16 = load i32, i32* @optind, align 4, !dbg !67, !tbaa !57
+  br i1 %15, label %17, label %21, !dbg !69
+
+; <label>:17:                                     ; preds = %11
+  %18 = getelementptr inbounds i8*, i8** %1, i32 %16, !dbg !70
+  %19 = load i8*, i8** %18, align 4, !dbg !70, !tbaa !49
+  %20 = tail call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i32 0, i32 0), i8* %19), !dbg !72
+  br label %71, !dbg !73
+
+; <label>:21:                                     ; preds = %11
+  %22 = add nsw i32 %16, 1, !dbg !74
+  %23 = getelementptr inbounds i8*, i8** %1, i32 %22, !dbg !75
+  %24 = load i8*, i8** %23, align 4, !dbg !75, !tbaa !49
+  %25 = tail call %0* @fopen(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i32 0, i32 0)), !dbg !76
+  tail call void @llvm.dbg.value(metadata %0* %25, i64 0, metadata !28, metadata !37), !dbg !41
+  %26 = icmp eq %0* %25, null, !dbg !77
+  br i1 %26, label %27, label %34, !dbg !78
+
+; <label>:27:                                     ; preds = %21
+  %28 = load i32, i32* @optind, align 4, !dbg !79, !tbaa !57
+  %29 = add nsw i32 %28, 1, !dbg !81
+  %30 = getelementptr inbounds i8*, i8** %1, i32 %29, !dbg !82
+  %31 = load i8*, i8** %30, align 4, !dbg !82, !tbaa !49
+  %32 = tail call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i32 0, i32 0), i8* %31), !dbg !83
+  %33 = tail call i32 @fclose(%0* nonnull %14), !dbg !84
+  br label %71, !dbg !85
+
+; <label>:34:                                     ; preds = %21, %7
+  %35 = phi %0* [ %25, %21 ], [ null, %7 ]
+  %36 = phi %0* [ %14, %21 ], [ null, %7 ]
+  %37 = tail call i32 @fseek(%0* %36, i32 0, i32 2), !dbg !86
+  %38 = tail call i32 @ftell(%0* %36), !dbg !87
+  tail call void @llvm.dbg.value(metadata i32 %38, i64 0, metadata !35, metadata !37), !dbg !88
+  %39 = tail call i8* @malloc(i32 %38), !dbg !89
+  tail call void @llvm.dbg.value(metadata i8* %39, i64 0, metadata !30, metadata !37), !dbg !91
+  %40 = icmp eq i8* %39, null, !dbg !92
+  br i1 %40, label %41, label %45, !dbg !93
+
+; <label>:41:                                     ; preds = %34
+  %42 = tail call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.4, i32 0, i32 0), i32 %38), !dbg !94
+  %43 = tail call i32 @fclose(%0* %35), !dbg !96
+  %44 = tail call i32 @fclose(%0* %36), !dbg !97
+  br label %71, !dbg !98
+
+; <label>:45:                                     ; preds = %34
+  tail call void @rewind(%0* %36), !dbg !99
+  %46 = tail call i32 @fread(i8* nonnull %39, i32 1, i32 %38, %0* %36), !dbg !100
+  %47 = icmp eq i32 %46, %38, !dbg !102
+  br i1 %47, label %48, label %50, !dbg !103
+
+; <label>:48:                                     ; preds = %45
+  %49 = icmp eq i32 %38, 0, !dbg !104
+  br i1 %49, label %61, label %54, !dbg !108
+
+; <label>:50:                                     ; preds = %45
+  tail call void @perror(i8* null) , !dbg !109
+  %51 = tail call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i32 0, i32 0), i32 %38), !dbg !111
+  tail call void @free(i8* nonnull %39), !dbg !112
+  %52 = tail call i32 @fclose(%0* %35), !dbg !113
+  %53 = tail call i32 @fclose(%0* %36), !dbg !114
+  br label %71, !dbg !115
+
+; <label>:54:                                     ; preds = %54, %48
+  %55 = phi i32 [ %59, %54 ], [ 0, %48 ]
+  %56 = getelementptr inbounds i8, i8* %39, i32 %55, !dbg !116
+  %57 = load i8, i8* %56, align 1, !dbg !116, !tbaa !118
+  %58 = tail call zeroext i8 @decode(i32 %55, i8 zeroext %57), !dbg !119
+  store i8 %58, i8* %56, align 1, !dbg !120, !tbaa !118
+  %59 = add nuw i32 %55, 1, !dbg !121
+  tail call void @llvm.dbg.value(metadata i32 %59, i64 0, metadata !32, metadata !37), !dbg !123
+  %60 = icmp eq i32 %59, %38, !dbg !108
+  br i1 %60, label %61, label %54, !dbg !108, !llvm.loop !124
+
+; <label>:61:                                     ; preds = %54, %48
+  %62 = tail call i32 @fwrite(i8* nonnull %39, i32 1, i32 %38, %0* %35), !dbg !126
+  %63 = icmp eq i32 %62, %38, !dbg !128
+  br i1 %63, label %68, label %64, !dbg !129
+
+; <label>:64:                                     ; preds = %61
+  %65 = tail call i32 @puts(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @str, i32 0, i32 0)), !dbg !130
+  tail call void @free(i8* nonnull %39), !dbg !132
+  %66 = tail call i32 @fclose(%0* %35), !dbg !133
+  %67 = tail call i32 @fclose(%0* %36), !dbg !134
+  br label %71, !dbg !135
+
+; <label>:68:                                     ; preds = %61
+  tail call void @free(i8* nonnull %39), !dbg !136
+  %69 = tail call i32 @fclose(%0* %35), !dbg !137
+  %70 = tail call i32 @fclose(%0* %36), !dbg !138
+  br label %71, !dbg !139
+
+; <label>:71:                                     ; preds = %68, %64, %50, %41, %27, %17, %4, %2
+  %72 = phi i32 [ 1, %4 ], [ -1, %50 ], [ -1, %64 ], [ 0, %68 ], [ -1, %41 ], [ -1, %27 ], [ -1, %17 ], [ -1, %2 ]
+  ret i32 %72, !dbg !140
+}
+
+declare i32 @getopt(i32, i8**, i8*) local_unnamed_addr
+
+; Function Attrs: nounwind
+declare noalias %0* @fopen(i8* nocapture readonly, i8* nocapture readonly) local_unnamed_addr
+
+; Function Attrs: nounwind
+declare i32 @fclose(%0* nocapture) local_unnamed_addr
+
+; Function Attrs: nounwind
+declare i32 @fseek(%0* nocapture, i32, i32) local_unnamed_addr
+
+; Function Attrs: nounwind
+declare i32 @ftell(%0* nocapture) local_unnamed_addr
+
+; Function Attrs: nounwind
+declare noalias i8* @malloc(i32) local_unnamed_addr
+
+; Function Attrs: nounwind
+declare void @rewind(%0* nocapture) local_unnamed_addr
+
+; Function Attrs: nounwind
+declare i32 @fread(i8* nocapture, i32, i32, %0* nocapture) local_unnamed_addr
+
+; Function Attrs: nounwind
+declare void @perror(i8* nocapture readonly) local_unnamed_addr
+
+; Function Attrs: nounwind
+declare void @free(i8* nocapture) local_unnamed_addr
+
+; Function Attrs: nounwind
+declare i32 @fwrite(i8* nocapture, i32, i32, %0* nocapture) local_unnamed_addr
+
+; Function Attrs: nounwind readnone
+declare void @llvm.dbg.value(metadata, i64, metadata, metadata)
+
+; Function Attrs: nounwind
+declare i32 @puts(i8* nocapture readonly)
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!11, !12}
+!llvm.ident = !{!13}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.9.0 (trunk 273884) (llvm/trunk 273897)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, globals: !3)
+!1 = !DIFile(filename: "crash.c", directory: "wasm/tests")
+!2 = !{}
+!3 = !{!4}
+!4 = distinct !DIGlobalVariable(name: "key", scope: !0, file: !1, line: 7, type: !5, isLocal: false, isDefinition: true, variable: [15 x i8]* @key)
+!5 = !DICompositeType(tag: DW_TAG_array_type, baseType: !6, size: 120, align: 8, elements: !9)
+!6 = !DIDerivedType(tag: DW_TAG_typedef, name: "uint8_t", file: !7, line: 185, baseType: !8)
+!7 = !DIFile(filename: "wasm/emscripten/system/include/libc/bits/alltypes.h", directory: "wasm/tests")
+!8 = !DIBasicType(name: "unsigned char", size: 8, align: 8, encoding: DW_ATE_unsigned_char)
+!9 = !{!10}
+!10 = !DISubrange(count: 15)
+!11 = !{i32 2, !"Dwarf Version", i32 4}
+!12 = !{i32 2, !"Debug Info Version", i32 3}
+!13 = !{!"clang version 3.9.0 (trunk 273884) (llvm/trunk 273897)"}
+!14 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 20, type: !15, isLocal: false, isDefinition: true, scopeLine: 20, flags: DIFlagPrototyped, isOptimized: true, unit: !0, variables: !21)
+!15 = !DISubroutineType(types: !16)
+!16 = !{!17, !17, !18}
+!17 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
+!18 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !19, size: 32, align: 32)
+!19 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !20, size: 32, align: 32)
+!20 = !DIBasicType(name: "char", size: 8, align: 8, encoding: DW_ATE_signed_char)
+!21 = !{!22, !23, !24, !28, !29, !30, !32, !35}
+!22 = !DILocalVariable(name: "argc", arg: 1, scope: !14, file: !1, line: 20, type: !17)
+!23 = !DILocalVariable(name: "argv", arg: 2, scope: !14, file: !1, line: 20, type: !18)
+!24 = !DILocalVariable(name: "ip", scope: !14, file: !1, line: 21, type: !25)
+!25 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !26, size: 32, align: 32)
+!26 = !DIDerivedType(tag: DW_TAG_typedef, name: "FILE", file: !7, line: 374, baseType: !27)
+!27 = !DICompositeType(tag: DW_TAG_structure_type, name: "_IO_FILE", file: !7, line: 374, flags: DIFlagFwdDecl)
+!28 = !DILocalVariable(name: "op", scope: !14, file: !1, line: 21, type: !25)
+!29 = !DILocalVariable(name: "c", scope: !14, file: !1, line: 22, type: !17)
+!30 = !DILocalVariable(name: "buf", scope: !14, file: !1, line: 24, type: !31)
+!31 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !6, size: 32, align: 32)
+!32 = !DILocalVariable(name: "pos", scope: !14, file: !1, line: 25, type: !33)
+!33 = !DIDerivedType(tag: DW_TAG_typedef, name: "size_t", file: !7, line: 124, baseType: !34)
+!34 = !DIBasicType(name: "long unsigned int", size: 32, align: 32, encoding: DW_ATE_unsigned)
+!35 = !DILocalVariable(name: "buf_size", scope: !14, file: !1, line: 25, type: !33)
+!36 = !{i64 0, !"_ZTSFiiPPcE"}
+!37 = !DIExpression()
+!38 = !DILocation(line: 20, column: 14, scope: !14)
+!39 = !DILocation(line: 20, column: 27, scope: !14)
+!40 = !DILocation(line: 21, column: 9, scope: !14)
+!41 = !DILocation(line: 21, column: 21, scope: !14)
+!42 = !DILocation(line: 27, column: 15, scope: !43)
+!43 = !DILexicalBlockFile(scope: !14, file: !1, discriminator: 1)
+!44 = !DILocation(line: 22, column: 7, scope: !14)
+!45 = !DILocation(line: 27, column: 3, scope: !43)
+!46 = !DILocation(line: 31, column: 22, scope: !47)
+!47 = distinct !DILexicalBlock(scope: !48, file: !1, line: 28, column: 16)
+!48 = distinct !DILexicalBlock(scope: !14, file: !1, line: 27, column: 47)
+!49 = !{!50, !50, i64 0}
+!50 = !{!"any pointer", !51, i64 0}
+!51 = !{!"omnipotent char", !52, i64 0}
+!52 = !{!"Simple C/C++ TBAA"}
+!53 = !DILocation(line: 31, column: 16, scope: !47)
+!54 = !DILocation(line: 31, column: 9, scope: !47)
+!55 = !DILocation(line: 39, column: 7, scope: !56)
+!56 = distinct !DILexicalBlock(scope: !14, file: !1, line: 39, column: 7)
+!57 = !{!58, !58, i64 0}
+!58 = !{!"int", !51, i64 0}
+!59 = !DILocation(line: 39, column: 14, scope: !56)
+!60 = !DILocation(line: 39, column: 18, scope: !56)
+!61 = !DILocation(line: 39, column: 7, scope: !14)
+!62 = !DILocation(line: 40, column: 22, scope: !63)
+!63 = distinct !DILexicalBlock(scope: !64, file: !1, line: 40, column: 9)
+!64 = distinct !DILexicalBlock(scope: !56, file: !1, line: 39, column: 26)
+!65 = !DILocation(line: 40, column: 16, scope: !63)
+!66 = !DILocation(line: 40, column: 14, scope: !63)
+!67 = !DILocation(line: 47, column: 27, scope: !68)
+!68 = distinct !DILexicalBlock(scope: !64, file: !1, line: 47, column: 9)
+!69 = !DILocation(line: 40, column: 9, scope: !64)
+!70 = !DILocation(line: 41, column: 42, scope: !71)
+!71 = distinct !DILexicalBlock(scope: !63, file: !1, line: 40, column: 44)
+!72 = !DILocation(line: 41, column: 7, scope: !71)
+!73 = !DILocation(line: 44, column: 7, scope: !71)
+!74 = !DILocation(line: 47, column: 34, scope: !68)
+!75 = !DILocation(line: 47, column: 22, scope: !68)
+!76 = !DILocation(line: 47, column: 16, scope: !68)
+!77 = !DILocation(line: 47, column: 14, scope: !68)
+!78 = !DILocation(line: 47, column: 9, scope: !64)
+!79 = !DILocation(line: 48, column: 47, scope: !80)
+!80 = distinct !DILexicalBlock(scope: !68, file: !1, line: 47, column: 48)
+!81 = !DILocation(line: 48, column: 54, scope: !80)
+!82 = !DILocation(line: 48, column: 42, scope: !80)
+!83 = !DILocation(line: 48, column: 7, scope: !80)
+!84 = !DILocation(line: 50, column: 7, scope: !80)
+!85 = !DILocation(line: 51, column: 7, scope: !80)
+!86 = !DILocation(line: 55, column: 3, scope: !14)
+!87 = !DILocation(line: 56, column: 14, scope: !14)
+!88 = !DILocation(line: 25, column: 15, scope: !14)
+!89 = !DILocation(line: 58, column: 15, scope: !90)
+!90 = distinct !DILexicalBlock(scope: !14, file: !1, line: 58, column: 7)
+!91 = !DILocation(line: 24, column: 12, scope: !14)
+!92 = !DILocation(line: 58, column: 13, scope: !90)
+!93 = !DILocation(line: 58, column: 7, scope: !14)
+!94 = !DILocation(line: 59, column: 5, scope: !95)
+!95 = distinct !DILexicalBlock(scope: !90, file: !1, line: 58, column: 34)
+!96 = !DILocation(line: 61, column: 5, scope: !95)
+!97 = !DILocation(line: 62, column: 5, scope: !95)
+!98 = !DILocation(line: 63, column: 5, scope: !95)
+!99 = !DILocation(line: 66, column: 3, scope: !14)
+!100 = !DILocation(line: 67, column: 7, scope: !101)
+!101 = distinct !DILexicalBlock(scope: !14, file: !1, line: 67, column: 7)
+!102 = !DILocation(line: 67, column: 61, scope: !101)
+!103 = !DILocation(line: 67, column: 7, scope: !14)
+!104 = !DILocation(line: 77, column: 21, scope: !105)
+!105 = !DILexicalBlockFile(scope: !106, file: !1, discriminator: 1)
+!106 = distinct !DILexicalBlock(scope: !107, file: !1, line: 77, column: 3)
+!107 = distinct !DILexicalBlock(scope: !14, file: !1, line: 77, column: 3)
+!108 = !DILocation(line: 77, column: 3, scope: !105)
+!109 = !DILocation(line: 68, column: 5, scope: !110)
+!110 = distinct !DILexicalBlock(scope: !101, file: !1, line: 67, column: 89)
+!111 = !DILocation(line: 69, column: 5, scope: !110)
+!112 = !DILocation(line: 71, column: 5, scope: !110)
+!113 = !DILocation(line: 72, column: 5, scope: !110)
+!114 = !DILocation(line: 73, column: 5, scope: !110)
+!115 = !DILocation(line: 74, column: 5, scope: !110)
+!116 = !DILocation(line: 78, column: 28, scope: !117)
+!117 = distinct !DILexicalBlock(scope: !106, file: !1, line: 77, column: 40)
+!118 = !{!51, !51, i64 0}
+!119 = !DILocation(line: 78, column: 16, scope: !117)
+!120 = !DILocation(line: 78, column: 14, scope: !117)
+!121 = !DILocation(line: 77, column: 36, scope: !122)
+!122 = !DILexicalBlockFile(scope: !106, file: !1, discriminator: 2)
+!123 = !DILocation(line: 25, column: 10, scope: !14)
+!124 = distinct !{!124, !125}
+!125 = !DILocation(line: 77, column: 3, scope: !14)
+!126 = !DILocation(line: 81, column: 7, scope: !127)
+!127 = distinct !DILexicalBlock(scope: !14, file: !1, line: 81, column: 7)
+!128 = !DILocation(line: 81, column: 62, scope: !127)
+!129 = !DILocation(line: 81, column: 7, scope: !14)
+!130 = !DILocation(line: 82, column: 5, scope: !131)
+!131 = distinct !DILexicalBlock(scope: !127, file: !1, line: 81, column: 90)
+!132 = !DILocation(line: 84, column: 5, scope: !131)
+!133 = !DILocation(line: 85, column: 5, scope: !131)
+!134 = !DILocation(line: 86, column: 5, scope: !131)
+!135 = !DILocation(line: 87, column: 5, scope: !131)
+!136 = !DILocation(line: 90, column: 3, scope: !14)
+!137 = !DILocation(line: 91, column: 3, scope: !14)
+!138 = !DILocation(line: 92, column: 3, scope: !14)
+!139 = !DILocation(line: 93, column: 3, scope: !14)
+!140 = !DILocation(line: 94, column: 1, scope: !14)
Index: test/DebugInfo/WebAssembly/wasm-store-results.ll
===================================================================
--- /dev/null
+++ test/DebugInfo/WebAssembly/wasm-store-results.ll
@@ -0,0 +1,462 @@
+; RUN: llc < %s -verify-machineinstrs -mtriple=wasm32-unknown-unknown | FileCheck %s
+; CHECK: #DEBUG_VALUE: main:argc <- [%vreg167+88]
+; CHECK: #DEBUG_VALUE: main:argv <- [%vreg167+84]
+; CHECK: __stack_pointer
+; CHECK: DW_TAG_variable
+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
+target triple = "wasm32-unknown-unknown"
+
+%0 = type opaque
+
+@key = external global [15 x i8], align 1
+@.str = external unnamed_addr constant [33 x i8], align 1
+@.str.1 = external unnamed_addr constant [2 x i8], align 1
+@optind = external global i32, align 4
+@.str.2 = external unnamed_addr constant [3 x i8], align 1
+@.str.3 = external unnamed_addr constant [24 x i8], align 1
+@.str.4 = external unnamed_addr constant [50 x i8], align 1
+@.str.5 = external unnamed_addr constant [31 x i8], align 1
+@.str.6 = external unnamed_addr constant [37 x i8], align 1
+
+; Function Attrs: nounwind
+declare zeroext i8 @decode(i32, i8 zeroext)
+
+; Function Attrs: nounwind readnone
+declare void @llvm.dbg.declare(metadata, metadata, metadata)
+
+; Function Attrs: nounwind
+declare i32 @usage(i8*)
+
+declare i32 @printf(i8*, ...)
+
+; Function Attrs: nounwind
+define hidden i32 @main(i32, i8**) !dbg !14 !type !21 {
+  %3 = alloca i32, align 4
+  %4 = alloca i32, align 4
+  %5 = alloca i8**, align 4
+  %6 = alloca %0*, align 4
+  %7 = alloca %0*, align 4
+  %8 = alloca i32, align 4
+  %9 = alloca i8*, align 4
+  %10 = alloca i32, align 4
+  %11 = alloca i32, align 4
+  store i32 0, i32* %3, align 4
+  store i32 %0, i32* %4, align 4
+  call void @llvm.dbg.declare(metadata i32* %4, metadata !22, metadata !23), !dbg !24
+  store i8** %1, i8*** %5, align 4
+  call void @llvm.dbg.declare(metadata i8*** %5, metadata !25, metadata !23), !dbg !26
+  call void @llvm.dbg.declare(metadata %0** %6, metadata !27, metadata !23), !dbg !31
+  store %0* null, %0** %6, align 4, !dbg !31
+  call void @llvm.dbg.declare(metadata %0** %7, metadata !32, metadata !23), !dbg !33
+  store %0* null, %0** %7, align 4, !dbg !33
+  call void @llvm.dbg.declare(metadata i32* %8, metadata !34, metadata !23), !dbg !35
+  call void @llvm.dbg.declare(metadata i8** %9, metadata !36, metadata !23), !dbg !38
+  call void @llvm.dbg.declare(metadata i32* %10, metadata !39, metadata !23), !dbg !42
+  call void @llvm.dbg.declare(metadata i32* %11, metadata !43, metadata !23), !dbg !44
+  br label %12, !dbg !45
+
+; <label>:12:                                     ; preds = %2
+  %13 = load i32, i32* %4, align 4, !dbg !46
+  %14 = load i8**, i8*** %5, align 4, !dbg !48
+  %15 = call i32 @getopt(i32 %13, i8** %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i32 0, i32 0)), !dbg !49
+  store i32 %15, i32* %8, align 4, !dbg !50
+  %16 = icmp ne i32 %15, -1, !dbg !51
+  br i1 %16, label %17, label %25, !dbg !52
+
+; <label>:17:                                     ; preds = %12
+  %18 = load i32, i32* %8, align 4, !dbg !53
+  switch i32 %18, label %24 [
+    i32 104, label %19
+    i32 63, label %19
+  ], !dbg !55
+
+; <label>:19:                                     ; preds = %17, %17
+  %20 = load i8**, i8*** %5, align 4, !dbg !56
+  %21 = getelementptr inbounds i8*, i8** %20, i32 0, !dbg !56
+  %22 = load i8*, i8** %21, align 4, !dbg !56
+  %23 = call i32 @usage(i8* %22), !dbg !58
+  store i32 %23, i32* %3, align 4, !dbg !59
+  br label %134, !dbg !59
+
+; <label>:24:                                     ; preds = %17
+  store i32 -1, i32* %3, align 4, !dbg !60
+  br label %134, !dbg !60
+
+; <label>:25:                                     ; preds = %12
+  %26 = load i32, i32* @optind, align 4, !dbg !61
+  %27 = add nsw i32 %26, 2, !dbg !63
+  %28 = load i32, i32* %4, align 4, !dbg !64
+  %29 = icmp slt i32 %27, %28, !dbg !65
+  br i1 %29, label %30, label %61, !dbg !66
+
+; <label>:30:                                     ; preds = %25
+  %31 = load i32, i32* @optind, align 4, !dbg !67
+  %32 = load i8**, i8*** %5, align 4, !dbg !70
+  %33 = getelementptr inbounds i8*, i8** %32, i32 %31, !dbg !70
+  %34 = load i8*, i8** %33, align 4, !dbg !70
+  %35 = call %0* @fopen(i8* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i32 0, i32 0)), !dbg !71
+  store %0* %35, %0** %6, align 4, !dbg !72
+  %36 = icmp ne %0* %35, null, !dbg !72
+  br i1 %36, label %43, label %37, !dbg !73
+
+; <label>:37:                                     ; preds = %30
+  %38 = load i32, i32* @optind, align 4, !dbg !74
+  %39 = load i8**, i8*** %5, align 4, !dbg !76
+  %40 = getelementptr inbounds i8*, i8** %39, i32 %38, !dbg !76
+  %41 = load i8*, i8** %40, align 4, !dbg !76
+  %42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i32 0, i32 0), i8* %41), !dbg !77
+  store i32 -1, i32* %3, align 4, !dbg !78
+  br label %134, !dbg !78
+
+; <label>:43:                                     ; preds = %30
+  %44 = load i32, i32* @optind, align 4, !dbg !79
+  %45 = add nsw i32 %44, 1, !dbg !81
+  %46 = load i8**, i8*** %5, align 4, !dbg !82
+  %47 = getelementptr inbounds i8*, i8** %46, i32 %45, !dbg !82
+  %48 = load i8*, i8** %47, align 4, !dbg !82
+  %49 = call %0* @fopen(i8* %48, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i32 0, i32 0)), !dbg !83
+  store %0* %49, %0** %7, align 4, !dbg !84
+  %50 = icmp ne %0* %49, null, !dbg !84
+  br i1 %50, label %60, label %51, !dbg !85
+
+; <label>:51:                                     ; preds = %43
+  %52 = load i32, i32* @optind, align 4, !dbg !86
+  %53 = add nsw i32 %52, 1, !dbg !88
+  %54 = load i8**, i8*** %5, align 4, !dbg !89
+  %55 = getelementptr inbounds i8*, i8** %54, i32 %53, !dbg !89
+  %56 = load i8*, i8** %55, align 4, !dbg !89
+  %57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i32 0, i32 0), i8* %56), !dbg !90
+  %58 = load %0*, %0** %6, align 4, !dbg !91
+  %59 = call i32 @fclose(%0* %58), !dbg !92
+  store i32 -1, i32* %3, align 4, !dbg !93
+  br label %134, !dbg !93
+
+; <label>:60:                                     ; preds = %43
+  br label %61, !dbg !94
+
+; <label>:61:                                     ; preds = %60, %25
+  %62 = load %0*, %0** %6, align 4, !dbg !95
+  %63 = call i32 @fseek(%0* %62, i32 0, i32 2), !dbg !96
+  %64 = load %0*, %0** %6, align 4, !dbg !97
+  %65 = call i32 @ftell(%0* %64), !dbg !98
+  store i32 %65, i32* %11, align 4, !dbg !99
+  %66 = load i32, i32* %11, align 4, !dbg !100
+  %67 = call i8* @malloc(i32 %66), !dbg !102
+  store i8* %67, i8** %9, align 4, !dbg !103
+  %68 = icmp ne i8* %67, null, !dbg !103
+  br i1 %68, label %76, label %69, !dbg !104
+
+; <label>:69:                                     ; preds = %61
+  %70 = load i32, i32* %11, align 4, !dbg !105
+  %71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.4, i32 0, i32 0), i32 %70), !dbg !107
+  %72 = load %0*, %0** %7, align 4, !dbg !108
+  %73 = call i32 @fclose(%0* %72), !dbg !109
+  %74 = load %0*, %0** %6, align 4, !dbg !110
+  %75 = call i32 @fclose(%0* %74), !dbg !111
+  store i32 -1, i32* %3, align 4, !dbg !112
+  br label %134, !dbg !112
+
+; <label>:76:                                     ; preds = %61
+  %77 = load %0*, %0** %6, align 4, !dbg !113
+  call void @rewind(%0* %77), !dbg !114
+  %78 = load i8*, i8** %9, align 4, !dbg !115
+  %79 = load i32, i32* %11, align 4, !dbg !117
+  %80 = udiv i32 %79, 1, !dbg !118
+  %81 = load %0*, %0** %6, align 4, !dbg !119
+  %82 = call i32 @fread(i8* %78, i32 1, i32 %80, %0* %81), !dbg !120
+  %83 = load i32, i32* %11, align 4, !dbg !121
+  %84 = udiv i32 %83, 1, !dbg !122
+  %85 = icmp ne i32 %82, %84, !dbg !123
+  br i1 %85, label %86, label %94, !dbg !124
+
+; <label>:86:                                     ; preds = %76
+  call void @perror(i8* null), !dbg !125
+  %87 = load i32, i32* %11, align 4, !dbg !127
+  %88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i32 0, i32 0), i32 %87), !dbg !128
+  %89 = load i8*, i8** %9, align 4, !dbg !129
+  call void @free(i8* %89), !dbg !130
+  %90 = load %0*, %0** %7, align 4, !dbg !131
+  %91 = call i32 @fclose(%0* %90), !dbg !132
+  %92 = load %0*, %0** %6, align 4, !dbg !133
+  %93 = call i32 @fclose(%0* %92), !dbg !134
+  store i32 -1, i32* %3, align 4, !dbg !135
+  br label %134, !dbg !135
+
+; <label>:94:                                     ; preds = %76
+  store i32 0, i32* %10, align 4, !dbg !136
+  br label %95, !dbg !138
+
+; <label>:95:                                     ; preds = %109, %94
+  %96 = load i32, i32* %10, align 4, !dbg !139
+  %97 = load i32, i32* %11, align 4, !dbg !142
+  %98 = icmp ult i32 %96, %97, !dbg !143
+  br i1 %98, label %99, label %112, !dbg !144
+
+; <label>:99:                                     ; preds = %95
+  %100 = load i32, i32* %10, align 4, !dbg !145
+  %101 = load i32, i32* %10, align 4, !dbg !147
+  %102 = load i8*, i8** %9, align 4, !dbg !148
+  %103 = getelementptr inbounds i8, i8* %102, i32 %101, !dbg !148
+  %104 = load i8, i8* %103, align 1, !dbg !148
+  %105 = call zeroext i8 @decode(i32 %100, i8 zeroext %104), !dbg !149
+  %106 = load i32, i32* %10, align 4, !dbg !150
+  %107 = load i8*, i8** %9, align 4, !dbg !151
+  %108 = getelementptr inbounds i8, i8* %107, i32 %106, !dbg !151
+  store i8 %105, i8* %108, align 1, !dbg !152
+  br label %109, !dbg !153
+
+; <label>:109:                                    ; preds = %99
+  %110 = load i32, i32* %10, align 4, !dbg !154
+  %111 = add i32 %110, 1, !dbg !154
+  store i32 %111, i32* %10, align 4, !dbg !154
+  br label %95, !dbg !156, !llvm.loop !157
+
+; <label>:112:                                    ; preds = %95
+  %113 = load i8*, i8** %9, align 4, !dbg !159
+  %114 = load i32, i32* %11, align 4, !dbg !161
+  %115 = udiv i32 %114, 1, !dbg !162
+  %116 = load %0*, %0** %7, align 4, !dbg !163
+  %117 = call i32 @fwrite(i8* %113, i32 1, i32 %115, %0* %116), !dbg !164
+  %118 = load i32, i32* %11, align 4, !dbg !165
+  %119 = udiv i32 %118, 1, !dbg !166
+  %120 = icmp ne i32 %117, %119, !dbg !167
+  br i1 %120, label %121, label %128, !dbg !168
+
+; <label>:121:                                    ; preds = %112
+  %122 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.6, i32 0, i32 0)), !dbg !169
+  %123 = load i8*, i8** %9, align 4, !dbg !171
+  call void @free(i8* %123), !dbg !172
+  %124 = load %0*, %0** %7, align 4, !dbg !173
+  %125 = call i32 @fclose(%0* %124), !dbg !174
+  %126 = load %0*, %0** %6, align 4, !dbg !175
+  %127 = call i32 @fclose(%0* %126), !dbg !176
+  store i32 -1, i32* %3, align 4, !dbg !177
+  br label %134, !dbg !177
+
+; <label>:128:                                    ; preds = %112
+  %129 = load i8*, i8** %9, align 4, !dbg !178
+  call void @free(i8* %129), !dbg !179
+  %130 = load %0*, %0** %7, align 4, !dbg !180
+  %131 = call i32 @fclose(%0* %130), !dbg !181
+  %132 = load %0*, %0** %6, align 4, !dbg !182
+  %133 = call i32 @fclose(%0* %132), !dbg !183
+  store i32 0, i32* %3, align 4, !dbg !184
+  br label %134, !dbg !184
+
+; <label>:134:                                    ; preds = %128, %121, %86, %69, %51, %37, %24, %19
+  %135 = load i32, i32* %3, align 4, !dbg !185
+  ret i32 %135, !dbg !185
+}
+
+declare i32 @getopt(i32, i8**, i8*)
+
+declare %0* @fopen(i8*, i8*)
+
+declare i32 @fclose(%0*)
+
+declare i32 @fseek(%0*, i32, i32)
+
+declare i32 @ftell(%0*)
+
+declare i8* @malloc(i32)
+
+declare void @rewind(%0*)
+
+declare i32 @fread(i8*, i32, i32, %0*)
+
+declare void @perror(i8*)
+
+declare void @free(i8*)
+
+declare i32 @fwrite(i8*, i32, i32, %0*)
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!11, !12}
+!llvm.ident = !{!13}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.9.0 (trunk 273884) (llvm/trunk 273897)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, globals: !3)
+!1 = !DIFile(filename: "crash.c", directory: "wasm/tests")
+!2 = !{}
+!3 = !{!4}
+!4 = distinct !DIGlobalVariable(name: "key", scope: !0, file: !1, line: 7, type: !5, isLocal: false, isDefinition: true, variable: [15 x i8]* @key)
+!5 = !DICompositeType(tag: DW_TAG_array_type, baseType: !6, size: 120, align: 8, elements: !9)
+!6 = !DIDerivedType(tag: DW_TAG_typedef, name: "uint8_t", file: !7, line: 185, baseType: !8)
+!7 = !DIFile(filename: "wasm/emscripten/system/include/libc/bits/alltypes.h", directory: "wasm/tests")
+!8 = !DIBasicType(name: "unsigned char", size: 8, align: 8, encoding: DW_ATE_unsigned_char)
+!9 = !{!10}
+!10 = !DISubrange(count: 15)
+!11 = !{i32 2, !"Dwarf Version", i32 4}
+!12 = !{i32 2, !"Debug Info Version", i32 3}
+!13 = !{!"clang version 3.9.0 (trunk 273884) (llvm/trunk 273897)"}
+!14 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 20, type: !15, isLocal: false, isDefinition: true, scopeLine: 20, flags: DIFlagPrototyped, isOptimized: false, unit: !0, variables: !2)
+!15 = !DISubroutineType(types: !16)
+!16 = !{!17, !17, !18}
+!17 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
+!18 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !19, size: 32, align: 32)
+!19 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !20, size: 32, align: 32)
+!20 = !DIBasicType(name: "char", size: 8, align: 8, encoding: DW_ATE_signed_char)
+!21 = !{i64 0, !"_ZTSFiiPPcE"}
+!22 = !DILocalVariable(name: "argc", arg: 1, scope: !14, file: !1, line: 20, type: !17)
+!23 = !DIExpression()
+!24 = !DILocation(line: 20, column: 14, scope: !14)
+!25 = !DILocalVariable(name: "argv", arg: 2, scope: !14, file: !1, line: 20, type: !18)
+!26 = !DILocation(line: 20, column: 27, scope: !14)
+!27 = !DILocalVariable(name: "ip", scope: !14, file: !1, line: 21, type: !28)
+!28 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !29, size: 32, align: 32)
+!29 = !DIDerivedType(tag: DW_TAG_typedef, name: "FILE", file: !7, line: 374, baseType: !30)
+!30 = !DICompositeType(tag: DW_TAG_structure_type, name: "_IO_FILE", file: !7, line: 374, flags: DIFlagFwdDecl)
+!31 = !DILocation(line: 21, column: 9, scope: !14)
+!32 = !DILocalVariable(name: "op", scope: !14, file: !1, line: 21, type: !28)
+!33 = !DILocation(line: 21, column: 21, scope: !14)
+!34 = !DILocalVariable(name: "c", scope: !14, file: !1, line: 22, type: !17)
+!35 = !DILocation(line: 22, column: 7, scope: !14)
+!36 = !DILocalVariable(name: "buf", scope: !14, file: !1, line: 24, type: !37)
+!37 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !6, size: 32, align: 32)
+!38 = !DILocation(line: 24, column: 12, scope: !14)
+!39 = !DILocalVariable(name: "pos", scope: !14, file: !1, line: 25, type: !40)
+!40 = !DIDerivedType(tag: DW_TAG_typedef, name: "size_t", file: !7, line: 124, baseType: !41)
+!41 = !DIBasicType(name: "long unsigned int", size: 32, align: 32, encoding: DW_ATE_unsigned)
+!42 = !DILocation(line: 25, column: 10, scope: !14)
+!43 = !DILocalVariable(name: "buf_size", scope: !14, file: !1, line: 25, type: !40)
+!44 = !DILocation(line: 25, column: 15, scope: !14)
+!45 = !DILocation(line: 27, column: 3, scope: !14)
+!46 = !DILocation(line: 27, column: 22, scope: !47)
+!47 = !DILexicalBlockFile(scope: !14, file: !1, discriminator: 1)
+!48 = !DILocation(line: 27, column: 28, scope: !47)
+!49 = !DILocation(line: 27, column: 15, scope: !47)
+!50 = !DILocation(line: 27, column: 13, scope: !47)
+!51 = !DILocation(line: 27, column: 40, scope: !47)
+!52 = !DILocation(line: 27, column: 3, scope: !47)
+!53 = !DILocation(line: 28, column: 13, scope: !54)
+!54 = distinct !DILexicalBlock(scope: !14, file: !1, line: 27, column: 47)
+!55 = !DILocation(line: 28, column: 5, scope: !54)
+!56 = !DILocation(line: 31, column: 22, scope: !57)
+!57 = distinct !DILexicalBlock(scope: !54, file: !1, line: 28, column: 16)
+!58 = !DILocation(line: 31, column: 16, scope: !57)
+!59 = !DILocation(line: 31, column: 9, scope: !57)
+!60 = !DILocation(line: 34, column: 8, scope: !57)
+!61 = !DILocation(line: 39, column: 7, scope: !62)
+!62 = distinct !DILexicalBlock(scope: !14, file: !1, line: 39, column: 7)
+!63 = !DILocation(line: 39, column: 14, scope: !62)
+!64 = !DILocation(line: 39, column: 20, scope: !62)
+!65 = !DILocation(line: 39, column: 18, scope: !62)
+!66 = !DILocation(line: 39, column: 7, scope: !14)
+!67 = !DILocation(line: 40, column: 27, scope: !68)
+!68 = distinct !DILexicalBlock(scope: !69, file: !1, line: 40, column: 9)
+!69 = distinct !DILexicalBlock(scope: !62, file: !1, line: 39, column: 26)
+!70 = !DILocation(line: 40, column: 22, scope: !68)
+!71 = !DILocation(line: 40, column: 16, scope: !68)
+!72 = !DILocation(line: 40, column: 14, scope: !68)
+!73 = !DILocation(line: 40, column: 9, scope: !69)
+!74 = !DILocation(line: 41, column: 47, scope: !75)
+!75 = distinct !DILexicalBlock(scope: !68, file: !1, line: 40, column: 44)
+!76 = !DILocation(line: 41, column: 42, scope: !75)
+!77 = !DILocation(line: 41, column: 7, scope: !75)
+!78 = !DILocation(line: 44, column: 7, scope: !75)
+!79 = !DILocation(line: 47, column: 27, scope: !80)
+!80 = distinct !DILexicalBlock(scope: !69, file: !1, line: 47, column: 9)
+!81 = !DILocation(line: 47, column: 34, scope: !80)
+!82 = !DILocation(line: 47, column: 22, scope: !80)
+!83 = !DILocation(line: 47, column: 16, scope: !80)
+!84 = !DILocation(line: 47, column: 14, scope: !80)
+!85 = !DILocation(line: 47, column: 9, scope: !69)
+!86 = !DILocation(line: 48, column: 47, scope: !87)
+!87 = distinct !DILexicalBlock(scope: !80, file: !1, line: 47, column: 48)
+!88 = !DILocation(line: 48, column: 54, scope: !87)
+!89 = !DILocation(line: 48, column: 42, scope: !87)
+!90 = !DILocation(line: 48, column: 7, scope: !87)
+!91 = !DILocation(line: 50, column: 14, scope: !87)
+!92 = !DILocation(line: 50, column: 7, scope: !87)
+!93 = !DILocation(line: 51, column: 7, scope: !87)
+!94 = !DILocation(line: 53, column: 3, scope: !69)
+!95 = !DILocation(line: 55, column: 9, scope: !14)
+!96 = !DILocation(line: 55, column: 3, scope: !14)
+!97 = !DILocation(line: 56, column: 20, scope: !14)
+!98 = !DILocation(line: 56, column: 14, scope: !14)
+!99 = !DILocation(line: 56, column: 12, scope: !14)
+!100 = !DILocation(line: 58, column: 22, scope: !101)
+!101 = distinct !DILexicalBlock(scope: !14, file: !1, line: 58, column: 7)
+!102 = !DILocation(line: 58, column: 15, scope: !101)
+!103 = !DILocation(line: 58, column: 13, scope: !101)
+!104 = !DILocation(line: 58, column: 7, scope: !14)
+!105 = !DILocation(line: 59, column: 66, scope: !106)
+!106 = distinct !DILexicalBlock(scope: !101, file: !1, line: 58, column: 34)
+!107 = !DILocation(line: 59, column: 5, scope: !106)
+!108 = !DILocation(line: 61, column: 12, scope: !106)
+!109 = !DILocation(line: 61, column: 5, scope: !106)
+!110 = !DILocation(line: 62, column: 12, scope: !106)
+!111 = !DILocation(line: 62, column: 5, scope: !106)
+!112 = !DILocation(line: 63, column: 5, scope: !106)
+!113 = !DILocation(line: 66, column: 10, scope: !14)
+!114 = !DILocation(line: 66, column: 3, scope: !14)
+!115 = !DILocation(line: 67, column: 13, scope: !116)
+!116 = distinct !DILexicalBlock(scope: !14, file: !1, line: 67, column: 7)
+!117 = !DILocation(line: 67, column: 32, scope: !116)
+!118 = !DILocation(line: 67, column: 41, scope: !116)
+!119 = !DILocation(line: 67, column: 57, scope: !116)
+!120 = !DILocation(line: 67, column: 7, scope: !116)
+!121 = !DILocation(line: 67, column: 64, scope: !116)
+!122 = !DILocation(line: 67, column: 73, scope: !116)
+!123 = !DILocation(line: 67, column: 61, scope: !116)
+!124 = !DILocation(line: 67, column: 7, scope: !14)
+!125 = !DILocation(line: 68, column: 5, scope: !126)
+!126 = distinct !DILexicalBlock(scope: !116, file: !1, line: 67, column: 89)
+!127 = !DILocation(line: 69, column: 47, scope: !126)
+!128 = !DILocation(line: 69, column: 5, scope: !126)
+!129 = !DILocation(line: 71, column: 10, scope: !126)
+!130 = !DILocation(line: 71, column: 5, scope: !126)
+!131 = !DILocation(line: 72, column: 12, scope: !126)
+!132 = !DILocation(line: 72, column: 5, scope: !126)
+!133 = !DILocation(line: 73, column: 12, scope: !126)
+!134 = !DILocation(line: 73, column: 5, scope: !126)
+!135 = !DILocation(line: 74, column: 5, scope: !126)
+!136 = !DILocation(line: 77, column: 12, scope: !137)
+!137 = distinct !DILexicalBlock(scope: !14, file: !1, line: 77, column: 3)
+!138 = !DILocation(line: 77, column: 8, scope: !137)
+!139 = !DILocation(line: 77, column: 17, scope: !140)
+!140 = !DILexicalBlockFile(scope: !141, file: !1, discriminator: 1)
+!141 = distinct !DILexicalBlock(scope: !137, file: !1, line: 77, column: 3)
+!142 = !DILocation(line: 77, column: 23, scope: !140)
+!143 = !DILocation(line: 77, column: 21, scope: !140)
+!144 = !DILocation(line: 77, column: 3, scope: !140)
+!145 = !DILocation(line: 78, column: 23, scope: !146)
+!146 = distinct !DILexicalBlock(scope: !141, file: !1, line: 77, column: 40)
+!147 = !DILocation(line: 78, column: 32, scope: !146)
+!148 = !DILocation(line: 78, column: 28, scope: !146)
+!149 = !DILocation(line: 78, column: 16, scope: !146)
+!150 = !DILocation(line: 78, column: 9, scope: !146)
+!151 = !DILocation(line: 78, column: 5, scope: !146)
+!152 = !DILocation(line: 78, column: 14, scope: !146)
+!153 = !DILocation(line: 79, column: 3, scope: !146)
+!154 = !DILocation(line: 77, column: 36, scope: !155)
+!155 = !DILexicalBlockFile(scope: !141, file: !1, discriminator: 2)
+!156 = !DILocation(line: 77, column: 3, scope: !155)
+!157 = distinct !{!157, !158}
+!158 = !DILocation(line: 77, column: 3, scope: !14)
+!159 = !DILocation(line: 81, column: 14, scope: !160)
+!160 = distinct !DILexicalBlock(scope: !14, file: !1, line: 81, column: 7)
+!161 = !DILocation(line: 81, column: 33, scope: !160)
+!162 = !DILocation(line: 81, column: 42, scope: !160)
+!163 = !DILocation(line: 81, column: 58, scope: !160)
+!164 = !DILocation(line: 81, column: 7, scope: !160)
+!165 = !DILocation(line: 81, column: 65, scope: !160)
+!166 = !DILocation(line: 81, column: 74, scope: !160)
+!167 = !DILocation(line: 81, column: 62, scope: !160)
+!168 = !DILocation(line: 81, column: 7, scope: !14)
+!169 = !DILocation(line: 82, column: 5, scope: !170)
+!170 = distinct !DILexicalBlock(scope: !160, file: !1, line: 81, column: 90)
+!171 = !DILocation(line: 84, column: 10, scope: !170)
+!172 = !DILocation(line: 84, column: 5, scope: !170)
+!173 = !DILocation(line: 85, column: 12, scope: !170)
+!174 = !DILocation(line: 85, column: 5, scope: !170)
+!175 = !DILocation(line: 86, column: 12, scope: !170)
+!176 = !DILocation(line: 86, column: 5, scope: !170)
+!177 = !DILocation(line: 87, column: 5, scope: !170)
+!178 = !DILocation(line: 90, column: 8, scope: !14)
+!179 = !DILocation(line: 90, column: 3, scope: !14)
+!180 = !DILocation(line: 91, column: 10, scope: !14)
+!181 = !DILocation(line: 91, column: 3, scope: !14)
+!182 = !DILocation(line: 92, column: 10, scope: !14)
+!183 = !DILocation(line: 92, column: 3, scope: !14)
+!184 = !DILocation(line: 93, column: 3, scope: !14)
+!185 = !DILocation(line: 94, column: 1, scope: !14)