; LLVM IR from bondhugula/pluto :: test (heat-2d)

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

@A = external dso_local global [2 x [4002 x [4002 x double]]], align 16

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

10:                                               ; preds = %135, %2
  %11 = load i32, ptr %6, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = icmp slt i64 %12, 1000
  br i1 %13, label %15, label %14

14:                                               ; preds = %10
  store i32 2, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %138

15:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 1, ptr %8, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %131, %15
  %17 = load i32, ptr %8, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = icmp slt i64 %18, 4001
  br i1 %19, label %21, label %20

20:                                               ; preds = %16
  store i32 5, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %134

21:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 1, ptr %9, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %127, %21
  %23 = load i32, ptr %9, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = icmp slt i64 %24, 4001
  br i1 %25, label %27, label %26

26:                                               ; preds = %22
  store i32 8, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %130

27:                                               ; preds = %22
  %28 = load i32, ptr %6, align 4, !tbaa !5
  %29 = srem i32 %28, 2
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [2 x [4002 x [4002 x double]]], ptr @A, i64 0, i64 %30
  %32 = load i32, ptr %8, align 4, !tbaa !5
  %33 = add nsw i32 %32, 1
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [4002 x [4002 x double]], ptr %31, i64 0, i64 %34
  %36 = load i32, ptr %9, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [4002 x double], ptr %35, i64 0, i64 %37
  %39 = load double, ptr %38, align 8, !tbaa !11
  %40 = load i32, ptr %6, align 4, !tbaa !5
  %41 = srem i32 %40, 2
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [2 x [4002 x [4002 x double]]], ptr @A, i64 0, i64 %42
  %44 = load i32, ptr %8, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [4002 x [4002 x double]], ptr %43, i64 0, i64 %45
  %47 = load i32, ptr %9, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [4002 x double], ptr %46, i64 0, i64 %48
  %50 = load double, ptr %49, align 8, !tbaa !11
  %51 = call double @llvm.fmuladd.f64(double -2.000000e+00, double %50, double %39)
  %52 = load i32, ptr %6, align 4, !tbaa !5
  %53 = srem i32 %52, 2
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [2 x [4002 x [4002 x double]]], ptr @A, i64 0, i64 %54
  %56 = load i32, ptr %8, align 4, !tbaa !5
  %57 = sub nsw i32 %56, 1
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [4002 x [4002 x double]], ptr %55, i64 0, i64 %58
  %60 = load i32, ptr %9, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [4002 x double], ptr %59, i64 0, i64 %61
  %63 = load double, ptr %62, align 8, !tbaa !11
  %64 = fadd double %51, %63
  %65 = load i32, ptr %6, align 4, !tbaa !5
  %66 = srem i32 %65, 2
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [2 x [4002 x [4002 x double]]], ptr @A, i64 0, i64 %67
  %69 = load i32, ptr %8, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [4002 x [4002 x double]], ptr %68, i64 0, i64 %70
  %72 = load i32, ptr %9, align 4, !tbaa !5
  %73 = add nsw i32 %72, 1
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [4002 x double], ptr %71, i64 0, i64 %74
  %76 = load double, ptr %75, align 8, !tbaa !11
  %77 = load i32, ptr %6, align 4, !tbaa !5
  %78 = srem i32 %77, 2
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds [2 x [4002 x [4002 x double]]], ptr @A, i64 0, i64 %79
  %81 = load i32, ptr %8, align 4, !tbaa !5
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds [4002 x [4002 x double]], ptr %80, i64 0, i64 %82
  %84 = load i32, ptr %9, align 4, !tbaa !5
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds [4002 x double], ptr %83, i64 0, i64 %85
  %87 = load double, ptr %86, align 8, !tbaa !11
  %88 = call double @llvm.fmuladd.f64(double -2.000000e+00, double %87, double %76)
  %89 = load i32, ptr %6, align 4, !tbaa !5
  %90 = srem i32 %89, 2
  %91 = sext i32 %90 to i64
  %92 = getelementptr inbounds [2 x [4002 x [4002 x double]]], ptr @A, i64 0, i64 %91
  %93 = load i32, ptr %8, align 4, !tbaa !5
  %94 = sext i32 %93 to i64
  %95 = getelementptr inbounds [4002 x [4002 x double]], ptr %92, i64 0, i64 %94
  %96 = load i32, ptr %9, align 4, !tbaa !5
  %97 = sub nsw i32 %96, 1
  %98 = sext i32 %97 to i64
  %99 = getelementptr inbounds [4002 x double], ptr %95, i64 0, i64 %98
  %100 = load double, ptr %99, align 8, !tbaa !11
  %101 = fadd double %88, %100
  %102 = fmul double 1.250000e-01, %101
  %103 = call double @llvm.fmuladd.f64(double 1.250000e-01, double %64, double %102)
  %104 = load i32, ptr %6, align 4, !tbaa !5
  %105 = srem i32 %104, 2
  %106 = sext i32 %105 to i64
  %107 = getelementptr inbounds [2 x [4002 x [4002 x double]]], ptr @A, i64 0, i64 %106
  %108 = load i32, ptr %8, align 4, !tbaa !5
  %109 = sext i32 %108 to i64
  %110 = getelementptr inbounds [4002 x [4002 x double]], ptr %107, i64 0, i64 %109
  %111 = load i32, ptr %9, align 4, !tbaa !5
  %112 = sext i32 %111 to i64
  %113 = getelementptr inbounds [4002 x double], ptr %110, i64 0, i64 %112
  %114 = load double, ptr %113, align 8, !tbaa !11
  %115 = fadd double %103, %114
  %116 = load i32, ptr %6, align 4, !tbaa !5
  %117 = add nsw i32 %116, 1
  %118 = srem i32 %117, 2
  %119 = sext i32 %118 to i64
  %120 = getelementptr inbounds [2 x [4002 x [4002 x double]]], ptr @A, i64 0, i64 %119
  %121 = load i32, ptr %8, align 4, !tbaa !5
  %122 = sext i32 %121 to i64
  %123 = getelementptr inbounds [4002 x [4002 x double]], ptr %120, i64 0, i64 %122
  %124 = load i32, ptr %9, align 4, !tbaa !5
  %125 = sext i32 %124 to i64
  %126 = getelementptr inbounds [4002 x double], ptr %123, i64 0, i64 %125
  store double %115, ptr %126, align 8, !tbaa !11
  br label %127

127:                                              ; preds = %27
  %128 = load i32, ptr %9, align 4, !tbaa !5
  %129 = add nsw i32 %128, 1
  store i32 %129, ptr %9, align 4, !tbaa !5
  br label %22, !llvm.loop !13

130:                                              ; preds = %26
  br label %131

131:                                              ; preds = %130
  %132 = load i32, ptr %8, align 4, !tbaa !5
  %133 = add nsw i32 %132, 1
  store i32 %133, ptr %8, align 4, !tbaa !5
  br label %16, !llvm.loop !15

134:                                              ; preds = %20
  br label %135

135:                                              ; preds = %134
  %136 = load i32, ptr %6, align 4, !tbaa !5
  %137 = add nsw i32 %136, 1
  store i32 %137, ptr %6, align 4, !tbaa !5
  br label %10, !llvm.loop !16

138:                                              ; preds = %14
  ret i32 0
}

; 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 speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #2

; 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}


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

@A = external dso_local local_unnamed_addr global [2 x [4002 x [4002 x double]]], align 16

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef i32 @main(i32 noundef %0, ptr nocapture noundef readnone %1) local_unnamed_addr #0 {
  br label %.preheader34

.preheader34:                                     ; preds = %2, %30
  %.03137 = phi i32 [ 0, %2 ], [ %31, %30 ]
  %3 = and i32 %.03137, 1
  %4 = xor i32 %3, 1
  %narrow = mul nuw nsw i32 %4, 128128032
  %5 = trunc i32 %.03137 to i1
  %.neg = select i1 %5, i64 -128128032, i64 0
  %6 = or disjoint i32 %narrow, 8
  %7 = zext nneg i32 %6 to i64
  %8 = add nsw i64 %.neg, %7
  %9 = and i32 %.03137, 1
  %10 = zext nneg i32 %9 to i64
  %11 = xor i32 %9, 1
  %12 = zext nneg i32 %11 to i64
  %diff.check47 = icmp ult i64 %8, 16
  br label %.preheader

13:                                               ; preds = %30
  ret i32 0

.preheader:                                       ; preds = %.preheader34, %middle.block
  %indvars.iv39 = phi i64 [ 1, %.preheader34 ], [ %indvars.iv.next40, %middle.block ]
  %indvars.iv.next40 = add nuw nsw i64 %indvars.iv39, 1
  %14 = add nsw i64 %indvars.iv39, -1
  %.phi.trans.insert = getelementptr inbounds [2 x [4002 x [4002 x double]]], ptr @A, i64 0, i64 %10, i64 %indvars.iv39, i64 1
  %.pre = load double, ptr %.phi.trans.insert, align 8, !tbaa !5
  br i1 %diff.check47, label %scalar.ph, label %vector.ph

vector.ph:                                        ; preds = %.preheader
  %vector.recur.init = insertelement <2 x double> poison, double %.pre, i64 1
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vector.recur = phi <2 x double> [ %vector.recur.init, %vector.ph ], [ %wide.load50, %vector.body ]
  %offset.idx = or disjoint i64 %index, 1
  %15 = getelementptr inbounds [2 x [4002 x [4002 x double]]], ptr @A, i64 0, i64 %10, i64 %indvars.iv.next40, i64 %offset.idx
  %wide.load = load <2 x double>, ptr %15, align 8, !tbaa !5
  %16 = getelementptr inbounds [2 x [4002 x [4002 x double]]], ptr @A, i64 0, i64 %10, i64 %14, i64 %offset.idx
  %wide.load49 = load <2 x double>, ptr %16, align 8, !tbaa !5
  %17 = add nuw nsw i64 %index, 2
  %18 = getelementptr inbounds [2 x [4002 x [4002 x double]]], ptr @A, i64 0, i64 %10, i64 %indvars.iv39, i64 %17
  %wide.load50 = load <2 x double>, ptr %18, align 16, !tbaa !5
  %19 = shufflevector <2 x double> %vector.recur, <2 x double> %wide.load50, <2 x i32> <i32 1, i32 2>
  %20 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %19, <2 x double> <double -2.000000e+00, double -2.000000e+00>, <2 x double> %wide.load)
  %21 = fadd <2 x double> %20, %wide.load49
  %22 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %19, <2 x double> <double -2.000000e+00, double -2.000000e+00>, <2 x double> %wide.load50)
  %23 = getelementptr inbounds [2 x [4002 x [4002 x double]]], ptr @A, i64 0, i64 %10, i64 %indvars.iv39, i64 %index
  %wide.load51 = load <2 x double>, ptr %23, align 16, !tbaa !5
  %24 = fadd <2 x double> %22, %wide.load51
  %25 = fmul <2 x double> %24, <double 1.250000e-01, double 1.250000e-01>
  %26 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %21, <2 x double> <double 1.250000e-01, double 1.250000e-01>, <2 x double> %25)
  %27 = fadd <2 x double> %19, %26
  %28 = getelementptr inbounds [2 x [4002 x [4002 x double]]], ptr @A, i64 0, i64 %12, i64 %indvars.iv39, i64 %offset.idx
  store <2 x double> %27, ptr %28, align 8, !tbaa !5
  %index.next = add nuw i64 %index, 2
  %29 = icmp eq i64 %index.next, 4000
  br i1 %29, label %middle.block, label %vector.body, !llvm.loop !9

30:                                               ; preds = %middle.block
  %31 = add nuw nsw i32 %.03137, 1
  %exitcond43.not = icmp eq i32 %31, 1000
  br i1 %exitcond43.not, label %13, label %.preheader34, !llvm.loop !13

middle.block:                                     ; preds = %vector.body, %scalar.ph
  %exitcond42.not = icmp eq i64 %indvars.iv.next40, 4001
  br i1 %exitcond42.not, label %30, label %.preheader, !llvm.loop !14

scalar.ph:                                        ; preds = %.preheader, %scalar.ph
  %32 = phi double [ %40, %scalar.ph ], [ %.pre, %.preheader ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %scalar.ph ], [ 1, %.preheader ]
  %33 = getelementptr inbounds [2 x [4002 x [4002 x double]]], ptr @A, i64 0, i64 %10, i64 %indvars.iv.next40, i64 %indvars.iv
  %34 = load double, ptr %33, align 8, !tbaa !5
  %35 = tail call double @llvm.fmuladd.f64(double %32, double -2.000000e+00, double %34)
  %36 = getelementptr inbounds [2 x [4002 x [4002 x double]]], ptr @A, i64 0, i64 %10, i64 %14, i64 %indvars.iv
  %37 = load double, ptr %36, align 8, !tbaa !5
  %38 = fadd double %35, %37
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %39 = getelementptr inbounds [2 x [4002 x [4002 x double]]], ptr @A, i64 0, i64 %10, i64 %indvars.iv39, i64 %indvars.iv.next
  %40 = load double, ptr %39, align 8, !tbaa !5
  %41 = tail call double @llvm.fmuladd.f64(double %32, double -2.000000e+00, double %40)
  %42 = add nsw i64 %indvars.iv, -1
  %43 = getelementptr inbounds [2 x [4002 x [4002 x double]]], ptr @A, i64 0, i64 %10, i64 %indvars.iv39, i64 %42
  %44 = load double, ptr %43, align 8, !tbaa !5
  %45 = fadd double %41, %44
  %46 = fmul double %45, 1.250000e-01
  %47 = tail call double @llvm.fmuladd.f64(double %38, double 1.250000e-01, double %46)
  %48 = fadd double %32, %47
  %49 = getelementptr inbounds [2 x [4002 x [4002 x double]]], ptr @A, i64 0, i64 %12, i64 %indvars.iv39, i64 %indvars.iv
  store double %48, ptr %49, align 8, !tbaa !5
  %exitcond.not = icmp eq i64 %indvars.iv.next, 4001
  br i1 %exitcond.not, label %middle.block, label %scalar.ph, !llvm.loop !15
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <2 x double> @llvm.fmuladd.v2f64(<2 x double>, <2 x double>, <2 x double>) #2

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) 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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}
!15 = distinct !{!15, !10, !11}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass