; LLVM IR from bondhugula/pluto :: examples/jacobi-2d-imper (jacobi-2d-imper)

; 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 [2000 x [2000 x double]], align 16
@b = external dso_local global [2000 x [2000 x double]], align 16
@.str.3 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @init_array() #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 willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
declare dso_local void @print_array() #0

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

7:                                                ; preds = %106, %0
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = icmp slt i32 %8, 1000
  br i1 %9, label %10, label %109

10:                                               ; preds = %7
  store i32 2, ptr %3, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %73, %10
  %12 = load i32, ptr %3, align 4, !tbaa !5
  %13 = icmp slt i32 %12, 1999
  br i1 %13, label %14, label %76

14:                                               ; preds = %11
  store i32 2, ptr %4, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %69, %14
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = icmp slt i32 %16, 1999
  br i1 %17, label %18, label %72

18:                                               ; preds = %15
  %19 = load i32, ptr %3, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [2000 x [2000 x double]], ptr @a, i64 0, i64 %20
  %22 = load i32, ptr %4, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [2000 x double], ptr %21, i64 0, i64 %23
  %25 = load double, ptr %24, align 8, !tbaa !9
  %26 = load i32, ptr %3, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [2000 x [2000 x double]], ptr @a, i64 0, i64 %27
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = sub nsw i32 %29, 1
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [2000 x double], ptr %28, i64 0, i64 %31
  %33 = load double, ptr %32, align 8, !tbaa !9
  %34 = fadd double %25, %33
  %35 = load i32, ptr %3, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [2000 x [2000 x double]], ptr @a, i64 0, i64 %36
  %38 = load i32, ptr %4, align 4, !tbaa !5
  %39 = add nsw i32 1, %38
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [2000 x double], ptr %37, i64 0, i64 %40
  %42 = load double, ptr %41, align 8, !tbaa !9
  %43 = fadd double %34, %42
  %44 = load i32, ptr %3, align 4, !tbaa !5
  %45 = add nsw i32 1, %44
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [2000 x [2000 x double]], ptr @a, i64 0, i64 %46
  %48 = load i32, ptr %4, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [2000 x double], ptr %47, i64 0, i64 %49
  %51 = load double, ptr %50, align 8, !tbaa !9
  %52 = fadd double %43, %51
  %53 = load i32, ptr %3, align 4, !tbaa !5
  %54 = sub nsw i32 %53, 1
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [2000 x [2000 x double]], ptr @a, i64 0, i64 %55
  %57 = load i32, ptr %4, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [2000 x double], ptr %56, i64 0, i64 %58
  %60 = load double, ptr %59, align 8, !tbaa !9
  %61 = fadd double %52, %60
  %62 = fmul double 2.000000e-01, %61
  %63 = load i32, ptr %3, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [2000 x [2000 x double]], ptr @b, i64 0, i64 %64
  %66 = load i32, ptr %4, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [2000 x double], ptr %65, i64 0, i64 %67
  store double %62, ptr %68, align 8, !tbaa !9
  br label %69

69:                                               ; preds = %18
  %70 = load i32, ptr %4, align 4, !tbaa !5
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr %4, align 4, !tbaa !5
  br label %15, !llvm.loop !11

72:                                               ; preds = %15
  br label %73

73:                                               ; preds = %72
  %74 = load i32, ptr %3, align 4, !tbaa !5
  %75 = add nsw i32 %74, 1
  store i32 %75, ptr %3, align 4, !tbaa !5
  br label %11, !llvm.loop !13

76:                                               ; preds = %11
  store i32 2, ptr %3, align 4, !tbaa !5
  br label %77

77:                                               ; preds = %102, %76
  %78 = load i32, ptr %3, align 4, !tbaa !5
  %79 = icmp slt i32 %78, 1999
  br i1 %79, label %80, label %105

80:                                               ; preds = %77
  store i32 2, ptr %4, align 4, !tbaa !5
  br label %81

81:                                               ; preds = %98, %80
  %82 = load i32, ptr %4, align 4, !tbaa !5
  %83 = icmp slt i32 %82, 1999
  br i1 %83, label %84, label %101

84:                                               ; preds = %81
  %85 = load i32, ptr %3, align 4, !tbaa !5
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds [2000 x [2000 x double]], ptr @b, i64 0, i64 %86
  %88 = load i32, ptr %4, align 4, !tbaa !5
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds [2000 x double], ptr %87, i64 0, i64 %89
  %91 = load double, ptr %90, align 8, !tbaa !9
  %92 = load i32, ptr %3, align 4, !tbaa !5
  %93 = sext i32 %92 to i64
  %94 = getelementptr inbounds [2000 x [2000 x double]], ptr @a, i64 0, i64 %93
  %95 = load i32, ptr %4, align 4, !tbaa !5
  %96 = sext i32 %95 to i64
  %97 = getelementptr inbounds [2000 x double], ptr %94, i64 0, i64 %96
  store double %91, ptr %97, align 8, !tbaa !9
  br label %98

98:                                               ; preds = %84
  %99 = load i32, ptr %4, align 4, !tbaa !5
  %100 = add nsw i32 %99, 1
  store i32 %100, ptr %4, align 4, !tbaa !5
  br label %81, !llvm.loop !14

101:                                              ; preds = %81
  br label %102

102:                                              ; preds = %101
  %103 = load i32, ptr %3, align 4, !tbaa !5
  %104 = add nsw i32 %103, 1
  store i32 %104, ptr %3, align 4, !tbaa !5
  br label %77, !llvm.loop !15

105:                                              ; preds = %77
  br label %106

106:                                              ; preds = %105
  %107 = load i32, ptr %2, align 4, !tbaa !5
  %108 = add nsw i32 %107, 1
  store i32 %108, ptr %2, align 4, !tbaa !5
  br label %7, !llvm.loop !16

109:                                              ; preds = %7
  %110 = call noalias ptr @fopen(ptr noundef @.str.3, ptr noundef @.str.4)
  %111 = icmp ne ptr %110, null
  br i1 %111, label %112, label %113

112:                                              ; preds = %109
  call void @print_array()
  br label %113

113:                                              ; preds = %112, %109
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  ret i32 0
}

declare noalias ptr @fopen(ptr noundef, ptr noundef) #2

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 = { "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 #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 = !{!"double", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}
!15 = distinct !{!15, !12}
!16 = distinct !{!16, !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"

@a = external dso_local local_unnamed_addr global [2000 x [2000 x double]], align 16
@b = external dso_local local_unnamed_addr global [2000 x [2000 x double]], align 16
@.str.3 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @init_array() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @print_array() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  tail call void @init_array()
  br label %.preheader31

.preheader31:                                     ; preds = %0, %45
  %.036 = phi i32 [ 0, %0 ], [ %46, %45 ]
  br label %.preheader29

.preheader29:                                     ; preds = %.preheader31, %.loopexit
  %indvars.iv38 = phi i64 [ 2, %.preheader31 ], [ %indvars.iv.next39, %.loopexit ]
  %indvars.iv.next39 = add nuw nsw i64 %indvars.iv38, 1
  %1 = add nsw i64 %indvars.iv38, -1
  %.phi.trans.insert = getelementptr inbounds [2000 x [2000 x double]], ptr @a, i64 0, i64 %indvars.iv38, i64 2
  %.pre = load double, ptr %.phi.trans.insert, align 16, !tbaa !5
  %vector.recur.init = insertelement <2 x double> poison, double %.pre, i64 1
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %.preheader29
  %index = phi i64 [ 0, %.preheader29 ], [ %index.next, %vector.body ]
  %vector.recur = phi <2 x double> [ %vector.recur.init, %.preheader29 ], [ %wide.load50, %vector.body ]
  %offset.idx = or disjoint i64 %index, 2
  %2 = or disjoint i64 %index, 1
  %3 = getelementptr inbounds [2000 x [2000 x double]], ptr @a, i64 0, i64 %indvars.iv38, i64 %2
  %4 = getelementptr inbounds i8, ptr %3, i64 16
  %wide.load = load <2 x double>, ptr %3, align 8, !tbaa !5
  %wide.load48 = load <2 x double>, ptr %4, align 8, !tbaa !5
  %5 = or disjoint i64 %index, 3
  %6 = getelementptr inbounds [2000 x [2000 x double]], ptr @a, i64 0, i64 %indvars.iv38, i64 %5
  %7 = getelementptr inbounds i8, ptr %6, i64 16
  %wide.load49 = load <2 x double>, ptr %6, align 8, !tbaa !5
  %wide.load50 = load <2 x double>, ptr %7, align 8, !tbaa !5
  %8 = shufflevector <2 x double> %vector.recur, <2 x double> %wide.load49, <2 x i32> <i32 1, i32 2>
  %9 = shufflevector <2 x double> %wide.load49, <2 x double> %wide.load50, <2 x i32> <i32 1, i32 2>
  %10 = fadd <2 x double> %8, %wide.load
  %11 = fadd <2 x double> %9, %wide.load48
  %12 = fadd <2 x double> %10, %wide.load49
  %13 = fadd <2 x double> %11, %wide.load50
  %14 = getelementptr inbounds [2000 x [2000 x double]], ptr @a, i64 0, i64 %indvars.iv.next39, i64 %offset.idx
  %15 = getelementptr inbounds i8, ptr %14, i64 16
  %wide.load51 = load <2 x double>, ptr %14, align 16, !tbaa !5
  %wide.load52 = load <2 x double>, ptr %15, align 16, !tbaa !5
  %16 = fadd <2 x double> %12, %wide.load51
  %17 = fadd <2 x double> %13, %wide.load52
  %18 = getelementptr inbounds [2000 x [2000 x double]], ptr @a, i64 0, i64 %1, i64 %offset.idx
  %19 = getelementptr inbounds i8, ptr %18, i64 16
  %wide.load53 = load <2 x double>, ptr %18, align 16, !tbaa !5
  %wide.load54 = load <2 x double>, ptr %19, align 16, !tbaa !5
  %20 = fadd <2 x double> %16, %wide.load53
  %21 = fadd <2 x double> %17, %wide.load54
  %22 = fmul <2 x double> %20, <double 2.000000e-01, double 2.000000e-01>
  %23 = fmul <2 x double> %21, <double 2.000000e-01, double 2.000000e-01>
  %24 = getelementptr inbounds [2000 x [2000 x double]], ptr @b, i64 0, i64 %indvars.iv38, i64 %offset.idx
  %25 = getelementptr inbounds i8, ptr %24, i64 16
  store <2 x double> %22, ptr %24, align 16, !tbaa !5
  store <2 x double> %23, ptr %25, align 16, !tbaa !5
  %index.next = add nuw i64 %index, 4
  %26 = icmp eq i64 %index.next, 1996
  br i1 %26, label %.loopexit, label %vector.body, !llvm.loop !9

.loopexit:                                        ; preds = %vector.body
  %vector.recur.extract = extractelement <2 x double> %wide.load50, i64 1
  %27 = getelementptr inbounds [2000 x [2000 x double]], ptr @a, i64 0, i64 %indvars.iv38, i64 1997
  %28 = load double, ptr %27, align 8, !tbaa !5
  %29 = fadd double %vector.recur.extract, %28
  %30 = getelementptr inbounds [2000 x [2000 x double]], ptr @a, i64 0, i64 %indvars.iv38, i64 1999
  %31 = load double, ptr %30, align 8, !tbaa !5
  %32 = fadd double %29, %31
  %33 = getelementptr inbounds [2000 x [2000 x double]], ptr @a, i64 0, i64 %indvars.iv.next39, i64 1998
  %34 = load double, ptr %33, align 16, !tbaa !5
  %35 = fadd double %32, %34
  %36 = getelementptr inbounds [2000 x [2000 x double]], ptr @a, i64 0, i64 %1, i64 1998
  %37 = load double, ptr %36, align 16, !tbaa !5
  %38 = fadd double %35, %37
  %39 = fmul double %38, 2.000000e-01
  %40 = getelementptr inbounds [2000 x [2000 x double]], ptr @b, i64 0, i64 %indvars.iv38, i64 1998
  store double %39, ptr %40, align 16, !tbaa !5
  %exitcond41.not = icmp eq i64 %indvars.iv.next39, 1999
  br i1 %exitcond41.not, label %.preheader, label %.preheader29, !llvm.loop !13

.preheader:                                       ; preds = %.loopexit, %.preheader.1
  %indvar = phi i64 [ %indvar.next.1, %.preheader.1 ], [ 0, %.loopexit ]
  %41 = mul nuw nsw i64 %indvar, 16000
  %42 = add nuw nsw i64 %41, 32016
  %scevgep = getelementptr i8, ptr @a, i64 %42
  %scevgep42 = getelementptr i8, ptr @b, i64 %42
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(15976) %scevgep, ptr noundef nonnull align 16 dereferenceable(15976) %scevgep42, i64 15976, i1 false), !tbaa !5
  %exitcond46.not = icmp eq i64 %indvar, 1996
  br i1 %exitcond46.not, label %45, label %.preheader.1, !llvm.loop !14

.preheader.1:                                     ; preds = %.preheader
  %43 = mul nuw i64 %indvar, 16000
  %44 = add nuw i64 %43, 48016
  %scevgep.1 = getelementptr i8, ptr @a, i64 %44
  %scevgep42.1 = getelementptr i8, ptr @b, i64 %44
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(15976) %scevgep.1, ptr noundef nonnull align 16 dereferenceable(15976) %scevgep42.1, i64 15976, i1 false), !tbaa !5
  %indvar.next.1 = add nuw nsw i64 %indvar, 2
  br label %.preheader

45:                                               ; preds = %.preheader
  %46 = add nuw nsw i32 %.036, 1
  %exitcond47.not = icmp eq i32 %46, 1000
  br i1 %exitcond47.not, label %47, label %.preheader31, !llvm.loop !15

47:                                               ; preds = %45
  %48 = tail call noalias ptr @fopen(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.4)
  %.not = icmp eq ptr %48, null
  br i1 %.not, label %50, label %49

49:                                               ; preds = %47
  tail call void @print_array()
  br label %50

50:                                               ; preds = %49, %47
  ret i32 0
}

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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 = { nofree nounwind "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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }

!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}


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