; LLVM IR from paintdream/DontStarveLuaJIT :: src/luajit/src (lj_snap)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%struct.GCtrace = type { %struct.GCRef, i8, i8, i8, i8, i32, %struct.GCRef, ptr, i32, i16, i16, ptr, ptr, %struct.GCRef, %struct.MRef, i32, i32, ptr, i32, i16, i16, i16, i16, i16, i16, i16, i8, i8 }
%struct.GCRef = type { i32 }
%struct.MRef = type { i32 }
%struct.SnapShot = type { i16, i16, i8, i8, i8, i8 }
%struct.anon.0 = type { i32, %struct.IRType1, i8, i8, i8 }
%struct.IRType1 = type { i8 }
%struct.anon = type { i16, i16, i16, i16 }
%union.IRIns = type { %struct.anon.0 }

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
define hidden ptr @lj_snap_regspmap(ptr noundef %0, i32 noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.GCtrace, ptr %14, i32 0, i32 11
  %16 = load ptr, ptr %15, align 8, !tbaa !11
  %17 = load i32, ptr %5, align 4, !tbaa !9
  %18 = zext i32 %17 to i64
  %19 = getelementptr inbounds %struct.SnapShot, ptr %16, i64 %18
  store ptr %19, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.GCtrace, ptr %20, i32 0, i32 12
  %22 = load ptr, ptr %21, align 8, !tbaa !16
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.SnapShot, ptr %23, i32 0, i32 0
  %25 = load i16, ptr %24, align 2, !tbaa !17
  %26 = zext i16 %25 to i64
  %27 = getelementptr inbounds i32, ptr %22, i64 %26
  store ptr %27, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = load i32, ptr %5, align 4, !tbaa !9
  %30 = call i64 @snap_renamefilter(ptr noundef %28, i32 noundef %29)
  store i64 %30, ptr %9, align 8, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  store i32 0, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %31

31:                                               ; preds = %116, %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.anon.0, ptr %32, i32 0, i32 2
  %34 = load i8, ptr %33, align 1, !tbaa !21
  %35 = zext i8 %34 to i32
  %36 = icmp eq i32 %35, 71
  br i1 %36, label %37, label %71

37:                                               ; preds = %31
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.anon, ptr %38, i32 0, i32 1
  %40 = load i16, ptr %39, align 2, !tbaa !21
  %41 = zext i16 %40 to i32
  %42 = and i32 %41, 1
  %43 = icmp ne i32 %42, 0
  br i1 %43, label %45, label %44

44:                                               ; preds = %37
  store i32 2, ptr %13, align 4
  br label %113

45:                                               ; preds = %37
  br label %46

46:                                               ; preds = %67, %45
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  %48 = load i32, ptr %10, align 4, !tbaa !9
  %49 = zext i32 %48 to i64
  %50 = getelementptr inbounds i32, ptr %47, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !9
  %52 = lshr i32 %51, 24
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.anon, ptr %53, i32 0, i32 0
  %55 = load i16, ptr %54, align 4, !tbaa !21
  %56 = zext i16 %55 to i32
  %57 = icmp eq i32 %52, %56
  br i1 %57, label %58, label %66

58:                                               ; preds = %46
  %59 = load ptr, ptr %8, align 8, !tbaa !5
  %60 = load i32, ptr %10, align 4, !tbaa !9
  %61 = add i32 %60, 1
  store i32 %61, ptr %10, align 4, !tbaa !9
  %62 = zext i32 %60 to i64
  %63 = getelementptr inbounds i32, ptr %59, i64 %62
  %64 = load i32, ptr %63, align 4, !tbaa !9
  %65 = and i32 %64, 65535
  store i32 %65, ptr %11, align 4, !tbaa !9
  br label %70

66:                                               ; preds = %46
  br label %67

67:                                               ; preds = %66
  %68 = load i32, ptr %10, align 4, !tbaa !9
  %69 = add i32 %68, 1
  store i32 %69, ptr %10, align 4, !tbaa !9
  br label %46

70:                                               ; preds = %58
  br label %85

71:                                               ; preds = %31
  %72 = load ptr, ptr %6, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.anon.0, ptr %72, i32 0, i32 2
  %74 = load i8, ptr %73, align 1, !tbaa !21
  %75 = zext i8 %74 to i32
  %76 = icmp eq i32 %75, 14
  br i1 %76, label %77, label %83

77:                                               ; preds = %71
  %78 = load ptr, ptr %6, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.anon, ptr %78, i32 0, i32 0
  %80 = load i16, ptr %79, align 4, !tbaa !21
  %81 = zext i16 %80 to i32
  %82 = add nsw i32 %81, 32768
  store i32 %82, ptr %11, align 4, !tbaa !9
  br label %84

83:                                               ; preds = %71
  store i32 2, ptr %13, align 4
  br label %113

84:                                               ; preds = %77
  br label %85

85:                                               ; preds = %84, %70
  %86 = load ptr, ptr %4, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.GCtrace, ptr %86, i32 0, i32 7
  %88 = load ptr, ptr %87, align 8, !tbaa !22
  %89 = load i32, ptr %11, align 4, !tbaa !9
  %90 = zext i32 %89 to i64
  %91 = getelementptr inbounds %union.IRIns, ptr %88, i64 %90
  %92 = getelementptr inbounds %struct.anon, ptr %91, i32 0, i32 3
  %93 = load i16, ptr %92, align 2, !tbaa !21
  %94 = zext i16 %93 to i32
  store i32 %94, ptr %12, align 4, !tbaa !9
  %95 = load i64, ptr %9, align 8, !tbaa !19
  %96 = load i32, ptr %11, align 4, !tbaa !9
  %97 = zext i32 %96 to i64
  %98 = and i64 %97, 63
  %99 = shl i64 1, %98
  %100 = and i64 %95, %99
  %101 = icmp ne i64 %100, 0
  br i1 %101, label %102, label %108

102:                                              ; preds = %85
  %103 = load ptr, ptr %4, align 8, !tbaa !5
  %104 = load i32, ptr %5, align 4, !tbaa !9
  %105 = load i32, ptr %11, align 4, !tbaa !9
  %106 = load i32, ptr %12, align 4, !tbaa !9
  %107 = call i32 @snap_renameref(ptr noundef %103, i32 noundef %104, i32 noundef %105, i32 noundef %106)
  store i32 %107, ptr %12, align 4, !tbaa !9
  br label %108

108:                                              ; preds = %102, %85
  %109 = load i32, ptr %12, align 4, !tbaa !9
  %110 = trunc i32 %109 to i16
  %111 = load ptr, ptr %6, align 8, !tbaa !5
  %112 = getelementptr inbounds %struct.anon, ptr %111, i32 0, i32 3
  store i16 %110, ptr %112, align 2, !tbaa !21
  store i32 0, ptr %13, align 4
  br label %113

113:                                              ; preds = %108, %83, %44
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  %114 = load i32, ptr %13, align 4
  switch i32 %114, label %121 [
    i32 0, label %115
    i32 2, label %119
  ]

115:                                              ; preds = %113
  br label %116

116:                                              ; preds = %115
  %117 = load ptr, ptr %6, align 8, !tbaa !5
  %118 = getelementptr inbounds %union.IRIns, ptr %117, i32 1
  store ptr %118, ptr %6, align 8, !tbaa !5
  br label %31

119:                                              ; preds = %113
  %120 = load ptr, ptr %6, align 8, !tbaa !5
  store i32 1, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret ptr %120

121:                                              ; preds = %113
  unreachable
}

; Function Attrs: nounwind uwtable
declare hidden i64 @snap_renamefilter(ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
declare hidden i32 @snap_renameref(ptr noundef, i32 noundef, i32 noundef, i32 noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 32}
!12 = !{!"GCtrace", !13, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !10, i64 8, !13, i64 12, !6, i64 16, !10, i64 24, !14, i64 28, !14, i64 30, !6, i64 32, !6, i64 40, !13, i64 48, !15, i64 52, !10, i64 56, !10, i64 60, !6, i64 64, !10, i64 72, !14, i64 76, !14, i64 78, !14, i64 80, !14, i64 82, !14, i64 84, !14, i64 86, !14, i64 88, !7, i64 90, !7, i64 91}
!13 = !{!"GCRef", !10, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = !{!"MRef", !10, i64 0}
!16 = !{!12, !6, i64 40}
!17 = !{!18, !14, i64 0}
!18 = !{!"SnapShot", !14, i64 0, !14, i64 2, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7}
!19 = !{!20, !20, i64 0}
!20 = !{!"long", !7, i64 0}
!21 = !{!7, !7, i64 0}
!22 = !{!12, !6, i64 16}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%struct.SnapShot = type { i16, i16, i8, i8, i8, i8 }
%union.IRIns = type { %struct.anon.0 }
%struct.anon.0 = type { i32, %struct.IRType1, i8, i8, i8 }
%struct.IRType1 = type { i8 }

; Function Attrs: nounwind uwtable
define hidden ptr @lj_snap_regspmap(ptr noundef %0, i32 noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 32
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = zext i32 %1 to i64
  %7 = getelementptr inbounds %struct.SnapShot, ptr %5, i64 %6
  %8 = getelementptr inbounds i8, ptr %0, i64 40
  %9 = load ptr, ptr %8, align 8, !tbaa !14
  %10 = load i16, ptr %7, align 2, !tbaa !15
  %11 = zext i16 %10 to i64
  %12 = getelementptr inbounds i32, ptr %9, i64 %11
  %13 = tail call i64 @snap_renamefilter(ptr noundef %0, i32 noundef %1)
  %14 = getelementptr inbounds i8, ptr %0, i64 16
  br label %15

15:                                               ; preds = %48, %3
  %.031 = phi ptr [ %2, %3 ], [ %51, %48 ]
  %.030 = phi i32 [ 0, %3 ], [ %.2, %48 ]
  %16 = getelementptr inbounds i8, ptr %.031, i64 5
  %17 = load i8, ptr %16, align 1, !tbaa !17
  switch i8 %17, label %52 [
    i8 71, label %18
    i8 14, label %33
  ]

18:                                               ; preds = %15
  %19 = getelementptr inbounds i8, ptr %.031, i64 2
  %20 = load i16, ptr %19, align 2, !tbaa !17
  %21 = and i16 %20, 1
  %.not = icmp eq i16 %21, 0
  br i1 %.not, label %52, label %.preheader

.preheader:                                       ; preds = %18
  %22 = load i16, ptr %.031, align 4, !tbaa !17
  %23 = zext i16 %22 to i32
  br label %24

24:                                               ; preds = %24, %.preheader
  %.1 = phi i32 [ %30, %24 ], [ %.030, %.preheader ]
  %25 = zext i32 %.1 to i64
  %26 = getelementptr inbounds i32, ptr %12, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !18
  %28 = lshr i32 %27, 24
  %29 = icmp eq i32 %28, %23
  %30 = add i32 %.1, 1
  br i1 %29, label %31, label %24

31:                                               ; preds = %24
  %32 = and i32 %27, 65535
  br label %37

33:                                               ; preds = %15
  %34 = load i16, ptr %.031, align 4, !tbaa !17
  %35 = zext i16 %34 to i32
  %36 = add nuw nsw i32 %35, 32768
  br label %37

37:                                               ; preds = %33, %31
  %.2 = phi i32 [ %30, %31 ], [ %.030, %33 ]
  %.029 = phi i32 [ %32, %31 ], [ %36, %33 ]
  %38 = load ptr, ptr %14, align 8, !tbaa !19
  %39 = zext nneg i32 %.029 to i64
  %40 = getelementptr inbounds %union.IRIns, ptr %38, i64 %39, i32 0, i32 3
  %41 = load i16, ptr %40, align 2, !tbaa !17
  %42 = zext i16 %41 to i32
  %43 = and i64 %39, 63
  %44 = shl nuw i64 1, %43
  %45 = and i64 %44, %13
  %.not33 = icmp eq i64 %45, 0
  br i1 %.not33, label %48, label %46

46:                                               ; preds = %37
  %47 = tail call i32 @snap_renameref(ptr noundef nonnull %0, i32 noundef %1, i32 noundef %.029, i32 noundef %42)
  br label %48

48:                                               ; preds = %46, %37
  %.028 = phi i32 [ %47, %46 ], [ %42, %37 ]
  %49 = trunc i32 %.028 to i16
  %50 = getelementptr inbounds i8, ptr %.031, i64 6
  store i16 %49, ptr %50, align 2, !tbaa !17
  %51 = getelementptr inbounds i8, ptr %.031, i64 8
  br label %15

52:                                               ; preds = %18, %15
  ret ptr %.031
}

; Function Attrs: nounwind uwtable
declare hidden i64 @snap_renamefilter(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i32 @snap_renameref(ptr noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

attributes #0 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !11, i64 32}
!6 = !{!"GCtrace", !7, i64 0, !9, i64 4, !9, i64 5, !9, i64 6, !9, i64 7, !8, i64 8, !7, i64 12, !11, i64 16, !8, i64 24, !12, i64 28, !12, i64 30, !11, i64 32, !11, i64 40, !7, i64 48, !13, i64 52, !8, i64 56, !8, i64 60, !11, i64 64, !8, i64 72, !12, i64 76, !12, i64 78, !12, i64 80, !12, i64 82, !12, i64 84, !12, i64 86, !12, i64 88, !9, i64 90, !9, i64 91}
!7 = !{!"GCRef", !8, i64 0}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"any pointer", !9, i64 0}
!12 = !{!"short", !9, i64 0}
!13 = !{!"MRef", !8, i64 0}
!14 = !{!6, !11, i64 40}
!15 = !{!16, !12, i64 0}
!16 = !{!"SnapShot", !12, i64 0, !12, i64 2, !9, i64 4, !9, i64 5, !9, i64 6, !9, i64 7}
!17 = !{!9, !9, i64 0}
!18 = !{!8, !8, i64 0}
!19 = !{!6, !11, i64 16}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass