; LLVM IR from aferikoglou/GenHLSOptimizer :: dataset/machsuite-stencil2d (stencil)

; 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"

; Function Attrs: nounwind uwtable
define dso_local void @stencil(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  br label %13

13:                                               ; preds = %3
  br label %14

14:                                               ; preds = %13
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %15

15:                                               ; preds = %81, %14
  %16 = load i32, ptr %7, align 4, !tbaa !9
  %17 = icmp slt i32 %16, 126
  br i1 %17, label %18, label %84

18:                                               ; preds = %15
  br label %19

19:                                               ; preds = %18
  br label %20

20:                                               ; preds = %19
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %21

21:                                               ; preds = %77, %20
  %22 = load i32, ptr %8, align 4, !tbaa !9
  %23 = icmp slt i32 %22, 62
  br i1 %23, label %24, label %80

24:                                               ; preds = %21
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %25

25:                                               ; preds = %24
  br label %26

26:                                               ; preds = %25
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %27

27:                                               ; preds = %65, %26
  %28 = load i32, ptr %9, align 4, !tbaa !9
  %29 = icmp slt i32 %28, 3
  br i1 %29, label %30, label %68

30:                                               ; preds = %27
  br label %31

31:                                               ; preds = %30
  br label %32

32:                                               ; preds = %31
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %33

33:                                               ; preds = %61, %32
  %34 = load i32, ptr %10, align 4, !tbaa !9
  %35 = icmp slt i32 %34, 3
  br i1 %35, label %36, label %64

36:                                               ; preds = %33
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = load i32, ptr %9, align 4, !tbaa !9
  %39 = mul nsw i32 %38, 3
  %40 = load i32, ptr %10, align 4, !tbaa !9
  %41 = add nsw i32 %39, %40
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds i32, ptr %37, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !9
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = load i32, ptr %7, align 4, !tbaa !9
  %47 = load i32, ptr %9, align 4, !tbaa !9
  %48 = add nsw i32 %46, %47
  %49 = mul nsw i32 %48, 64
  %50 = load i32, ptr %8, align 4, !tbaa !9
  %51 = add nsw i32 %49, %50
  %52 = load i32, ptr %10, align 4, !tbaa !9
  %53 = add nsw i32 %51, %52
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds i32, ptr %45, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !9
  %57 = mul nsw i32 %44, %56
  store i32 %57, ptr %12, align 4, !tbaa !9
  %58 = load i32, ptr %12, align 4, !tbaa !9
  %59 = load i32, ptr %11, align 4, !tbaa !9
  %60 = add nsw i32 %59, %58
  store i32 %60, ptr %11, align 4, !tbaa !9
  br label %61

61:                                               ; preds = %36
  %62 = load i32, ptr %10, align 4, !tbaa !9
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %10, align 4, !tbaa !9
  br label %33, !llvm.loop !11

64:                                               ; preds = %33
  br label %65

65:                                               ; preds = %64
  %66 = load i32, ptr %9, align 4, !tbaa !9
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %9, align 4, !tbaa !9
  br label %27, !llvm.loop !13

68:                                               ; preds = %27
  %69 = load i32, ptr %11, align 4, !tbaa !9
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  %71 = load i32, ptr %7, align 4, !tbaa !9
  %72 = mul nsw i32 %71, 64
  %73 = load i32, ptr %8, align 4, !tbaa !9
  %74 = add nsw i32 %72, %73
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds i32, ptr %70, i64 %75
  store i32 %69, ptr %76, align 4, !tbaa !9
  br label %77

77:                                               ; preds = %68
  %78 = load i32, ptr %8, align 4, !tbaa !9
  %79 = add nsw i32 %78, 1
  store i32 %79, ptr %8, align 4, !tbaa !9
  br label %21, !llvm.loop !14

80:                                               ; preds = %21
  br label %81

81:                                               ; preds = %80
  %82 = load i32, ptr %7, align 4, !tbaa !9
  %83 = add nsw i32 %82, 1
  store i32 %83, ptr %7, align 4, !tbaa !9
  br label %15, !llvm.loop !15

84:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  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 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  ret void
}

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

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

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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}
!15 = distinct !{!15, !12}


; 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"

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @stencil(ptr nocapture noundef readonly %0, ptr nocapture noundef writeonly %1, ptr nocapture noundef readonly %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %2, i64 24
  %5 = getelementptr inbounds i8, ptr %2, i64 4
  %invariant.gep = getelementptr inbounds i8, ptr %0, i64 4
  %6 = getelementptr inbounds i8, ptr %2, i64 8
  %invariant.gep40 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = getelementptr inbounds i8, ptr %2, i64 12
  %8 = getelementptr inbounds i8, ptr %2, i64 16
  %invariant.gep42 = getelementptr inbounds i8, ptr %0, i64 4
  %9 = getelementptr inbounds i8, ptr %2, i64 20
  %invariant.gep44 = getelementptr inbounds i8, ptr %0, i64 8
  %10 = getelementptr inbounds i8, ptr %2, i64 28
  %invariant.gep46 = getelementptr i8, ptr %0, i64 4
  %11 = getelementptr inbounds i8, ptr %2, i64 32
  %invariant.gep48 = getelementptr i8, ptr %0, i64 8
  %scevgep = getelementptr i8, ptr %1, i64 32248
  %scevgep50 = getelementptr i8, ptr %2, i64 36
  %scevgep51 = getelementptr i8, ptr %0, i64 32768
  %bound0 = icmp ugt ptr %scevgep50, %1
  %bound1 = icmp ugt ptr %scevgep, %2
  %found.conflict = and i1 %bound0, %bound1
  %bound052 = icmp ugt ptr %scevgep51, %1
  %bound153 = icmp ugt ptr %scevgep, %0
  %found.conflict54 = and i1 %bound052, %bound153
  %conflict.rdx = or i1 %found.conflict, %found.conflict54
  br label %.preheader26

.preheader26:                                     ; preds = %3, %.loopexit
  %indvars.iv36 = phi i64 [ 0, %3 ], [ %13, %.loopexit ]
  %12 = shl nuw nsw i64 %indvars.iv36, 6
  %13 = add nuw nsw i64 %indvars.iv36, 1
  %14 = shl nuw nsw i64 %13, 6
  %15 = shl i64 %indvars.iv36, 6
  %16 = add i64 %15, 128
  br i1 %conflict.rdx, label %.preheader25.preheader, label %vector.body.preheader

vector.body.preheader:                            ; preds = %.preheader26
  %17 = load i32, ptr %2, align 4, !tbaa !5, !alias.scope !9
  %broadcast.splatinsert = insertelement <4 x i32> poison, i32 %17, i64 0
  %broadcast.splat = shufflevector <4 x i32> %broadcast.splatinsert, <4 x i32> poison, <4 x i32> zeroinitializer
  %18 = load i32, ptr %5, align 4, !tbaa !5, !alias.scope !9
  %broadcast.splatinsert56 = insertelement <4 x i32> poison, i32 %18, i64 0
  %broadcast.splat57 = shufflevector <4 x i32> %broadcast.splatinsert56, <4 x i32> poison, <4 x i32> zeroinitializer
  %19 = load i32, ptr %6, align 4, !tbaa !5, !alias.scope !9
  %broadcast.splatinsert59 = insertelement <4 x i32> poison, i32 %19, i64 0
  %broadcast.splat60 = shufflevector <4 x i32> %broadcast.splatinsert59, <4 x i32> poison, <4 x i32> zeroinitializer
  %20 = load i32, ptr %7, align 4, !tbaa !5, !alias.scope !9
  %broadcast.splatinsert62 = insertelement <4 x i32> poison, i32 %20, i64 0
  %broadcast.splat63 = shufflevector <4 x i32> %broadcast.splatinsert62, <4 x i32> poison, <4 x i32> zeroinitializer
  %21 = load i32, ptr %8, align 4, !tbaa !5, !alias.scope !9
  %broadcast.splatinsert65 = insertelement <4 x i32> poison, i32 %21, i64 0
  %broadcast.splat66 = shufflevector <4 x i32> %broadcast.splatinsert65, <4 x i32> poison, <4 x i32> zeroinitializer
  %22 = load i32, ptr %9, align 4, !tbaa !5, !alias.scope !9
  %broadcast.splatinsert68 = insertelement <4 x i32> poison, i32 %22, i64 0
  %broadcast.splat69 = shufflevector <4 x i32> %broadcast.splatinsert68, <4 x i32> poison, <4 x i32> zeroinitializer
  %23 = load i32, ptr %4, align 4, !tbaa !5, !alias.scope !9
  %broadcast.splatinsert71 = insertelement <4 x i32> poison, i32 %23, i64 0
  %broadcast.splat72 = shufflevector <4 x i32> %broadcast.splatinsert71, <4 x i32> poison, <4 x i32> zeroinitializer
  %24 = load i32, ptr %10, align 4, !tbaa !5, !alias.scope !9
  %broadcast.splatinsert74 = insertelement <4 x i32> poison, i32 %24, i64 0
  %broadcast.splat75 = shufflevector <4 x i32> %broadcast.splatinsert74, <4 x i32> poison, <4 x i32> zeroinitializer
  %25 = load i32, ptr %11, align 4, !tbaa !5, !alias.scope !9
  %broadcast.splatinsert77 = insertelement <4 x i32> poison, i32 %25, i64 0
  %broadcast.splat78 = shufflevector <4 x i32> %broadcast.splatinsert77, <4 x i32> poison, <4 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body.preheader, %vector.body
  %index = phi i64 [ %index.next, %vector.body ], [ 0, %vector.body.preheader ]
  %26 = add nuw nsw i64 %12, %index
  %27 = getelementptr inbounds i32, ptr %0, i64 %26
  %wide.load = load <4 x i32>, ptr %27, align 4, !tbaa !5, !alias.scope !12
  %28 = mul nsw <4 x i32> %wide.load, %broadcast.splat
  %29 = getelementptr inbounds i32, ptr %invariant.gep, i64 %26
  %wide.load55 = load <4 x i32>, ptr %29, align 4, !tbaa !5, !alias.scope !12
  %30 = mul nsw <4 x i32> %wide.load55, %broadcast.splat57
  %31 = add nsw <4 x i32> %30, %28
  %32 = getelementptr inbounds i32, ptr %invariant.gep40, i64 %26
  %wide.load58 = load <4 x i32>, ptr %32, align 4, !tbaa !5, !alias.scope !12
  %33 = mul nsw <4 x i32> %wide.load58, %broadcast.splat60
  %34 = add nsw <4 x i32> %33, %31
  %35 = add nuw nsw i64 %14, %index
  %36 = getelementptr inbounds i32, ptr %0, i64 %35
  %wide.load61 = load <4 x i32>, ptr %36, align 4, !tbaa !5, !alias.scope !12
  %37 = mul nsw <4 x i32> %wide.load61, %broadcast.splat63
  %38 = add nsw <4 x i32> %37, %34
  %39 = getelementptr inbounds i32, ptr %invariant.gep42, i64 %35
  %wide.load64 = load <4 x i32>, ptr %39, align 4, !tbaa !5, !alias.scope !12
  %40 = mul nsw <4 x i32> %wide.load64, %broadcast.splat66
  %41 = add nsw <4 x i32> %40, %38
  %42 = getelementptr inbounds i32, ptr %invariant.gep44, i64 %35
  %wide.load67 = load <4 x i32>, ptr %42, align 4, !tbaa !5, !alias.scope !12
  %43 = mul nsw <4 x i32> %wide.load67, %broadcast.splat69
  %44 = add nsw <4 x i32> %43, %41
  %45 = add nuw nsw i64 %16, %index
  %46 = getelementptr inbounds i32, ptr %0, i64 %45
  %wide.load70 = load <4 x i32>, ptr %46, align 4, !tbaa !5, !alias.scope !12
  %47 = mul nsw <4 x i32> %wide.load70, %broadcast.splat72
  %48 = add nsw <4 x i32> %47, %44
  %49 = getelementptr i32, ptr %invariant.gep46, i64 %45
  %wide.load73 = load <4 x i32>, ptr %49, align 4, !tbaa !5, !alias.scope !12
  %50 = mul nsw <4 x i32> %wide.load73, %broadcast.splat75
  %51 = add nsw <4 x i32> %50, %48
  %52 = getelementptr i32, ptr %invariant.gep48, i64 %45
  %wide.load76 = load <4 x i32>, ptr %52, align 4, !tbaa !5, !alias.scope !12
  %53 = mul nsw <4 x i32> %wide.load76, %broadcast.splat78
  %54 = add nsw <4 x i32> %53, %51
  %55 = getelementptr inbounds i32, ptr %1, i64 %26
  store <4 x i32> %54, ptr %55, align 4, !tbaa !5, !alias.scope !14, !noalias !16
  %index.next = add nuw i64 %index, 4
  %56 = icmp eq i64 %index.next, 60
  br i1 %56, label %.preheader25.preheader, label %vector.body, !llvm.loop !17

.preheader25.preheader:                           ; preds = %vector.body, %.preheader26
  %indvars.iv.ph = phi i64 [ 0, %.preheader26 ], [ 60, %vector.body ]
  br label %.preheader25

.preheader25:                                     ; preds = %.preheader25.preheader, %.preheader25
  %indvars.iv = phi i64 [ %indvars.iv.next, %.preheader25 ], [ %indvars.iv.ph, %.preheader25.preheader ]
  %57 = add nuw nsw i64 %12, %indvars.iv
  %58 = load i32, ptr %2, align 4, !tbaa !5
  %59 = getelementptr inbounds i32, ptr %0, i64 %57
  %60 = load i32, ptr %59, align 4, !tbaa !5
  %61 = mul nsw i32 %60, %58
  %62 = load i32, ptr %5, align 4, !tbaa !5
  %gep = getelementptr inbounds i32, ptr %invariant.gep, i64 %57
  %63 = load i32, ptr %gep, align 4, !tbaa !5
  %64 = mul nsw i32 %63, %62
  %65 = load i32, ptr %6, align 4, !tbaa !5
  %gep41 = getelementptr inbounds i32, ptr %invariant.gep40, i64 %57
  %66 = load i32, ptr %gep41, align 4, !tbaa !5
  %67 = mul nsw i32 %66, %65
  %68 = add nuw nsw i64 %14, %indvars.iv
  %69 = load i32, ptr %7, align 4, !tbaa !5
  %70 = getelementptr inbounds i32, ptr %0, i64 %68
  %71 = load i32, ptr %70, align 4, !tbaa !5
  %72 = mul nsw i32 %71, %69
  %gep43 = getelementptr inbounds i32, ptr %invariant.gep42, i64 %68
  %73 = load <2 x i32>, ptr %gep43, align 4, !tbaa !5
  %74 = add nuw nsw i64 %16, %indvars.iv
  %75 = getelementptr inbounds i32, ptr %0, i64 %74
  %76 = load <2 x i32>, ptr %75, align 4, !tbaa !5
  %77 = load <4 x i32>, ptr %8, align 4, !tbaa !5
  %78 = shufflevector <2 x i32> %73, <2 x i32> %76, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
  %79 = mul nsw <4 x i32> %78, %77
  %80 = load i32, ptr %11, align 4, !tbaa !5
  %gep49 = getelementptr i32, ptr %invariant.gep48, i64 %74
  %81 = load i32, ptr %gep49, align 4, !tbaa !5
  %82 = mul nsw i32 %81, %80
  %83 = tail call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %79)
  %op.rdx = add i32 %83, %64
  %op.rdx79 = add i32 %61, %67
  %op.rdx80 = add i32 %72, %82
  %op.rdx81 = add i32 %op.rdx, %op.rdx79
  %op.rdx82 = add i32 %op.rdx81, %op.rdx80
  %84 = getelementptr inbounds i32, ptr %1, i64 %57
  store i32 %op.rdx82, ptr %84, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 62
  br i1 %exitcond.not, label %.loopexit, label %.preheader25, !llvm.loop !21

.loopexit:                                        ; preds = %.preheader25
  %exitcond39.not = icmp eq i64 %13, 126
  br i1 %exitcond39.not, label %85, label %.preheader26, !llvm.loop !22

85:                                               ; preds = %.loopexit
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.vector.reduce.add.v4i32(<4 x i32>) #1

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: readwrite) 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 #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10}
!10 = distinct !{!10, !11}
!11 = distinct !{!11, !"LVerDomain"}
!12 = !{!13}
!13 = distinct !{!13, !11}
!14 = !{!15}
!15 = distinct !{!15, !11}
!16 = !{!10, !13}
!17 = distinct !{!17, !18, !19, !20}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!"llvm.loop.isvectorized", i32 1}
!20 = !{!"llvm.loop.unroll.runtime.disable"}
!21 = distinct !{!21, !18, !19}
!22 = distinct !{!22, !18}


; Effective O3 passes: GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass,VectorCombinePass