; LLVM IR from bondhugula/pluto :: examples/jacobi-1d-imper (jacobi-1d-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 [2000000 x double], align 16
@b = external dso_local global [2000000 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: 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
declare dso_local void @init_array() #1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  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 @init_array()
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %5

5:                                                ; preds = %52, %0
  %6 = load i32, ptr %2, align 4, !tbaa !5
  %7 = icmp slt i32 %6, 1000
  br i1 %7, label %8, label %55

8:                                                ; preds = %5
  store i32 2, ptr %3, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %33, %8
  %10 = load i32, ptr %3, align 4, !tbaa !5
  %11 = icmp slt i32 %10, 1999999
  br i1 %11, label %12, label %36

12:                                               ; preds = %9
  %13 = load i32, ptr %3, align 4, !tbaa !5
  %14 = sub nsw i32 %13, 1
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [2000000 x double], ptr @a, i64 0, i64 %15
  %17 = load double, ptr %16, align 8, !tbaa !9
  %18 = load i32, ptr %3, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [2000000 x double], ptr @a, i64 0, i64 %19
  %21 = load double, ptr %20, align 8, !tbaa !9
  %22 = fadd double %17, %21
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = add nsw i32 %23, 1
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [2000000 x double], ptr @a, i64 0, i64 %25
  %27 = load double, ptr %26, align 8, !tbaa !9
  %28 = fadd double %22, %27
  %29 = fmul double 3.333300e-01, %28
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [2000000 x double], ptr @b, i64 0, i64 %31
  store double %29, ptr %32, align 8, !tbaa !9
  br label %33

33:                                               ; preds = %12
  %34 = load i32, ptr %3, align 4, !tbaa !5
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %3, align 4, !tbaa !5
  br label %9, !llvm.loop !11

36:                                               ; preds = %9
  store i32 2, ptr %4, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %48, %36
  %38 = load i32, ptr %4, align 4, !tbaa !5
  %39 = icmp slt i32 %38, 1999999
  br i1 %39, label %40, label %51

40:                                               ; preds = %37
  %41 = load i32, ptr %4, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [2000000 x double], ptr @b, i64 0, i64 %42
  %44 = load double, ptr %43, align 8, !tbaa !9
  %45 = load i32, ptr %4, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [2000000 x double], ptr @a, i64 0, i64 %46
  store double %44, ptr %47, align 8, !tbaa !9
  br label %48

48:                                               ; preds = %40
  %49 = load i32, ptr %4, align 4, !tbaa !5
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %4, align 4, !tbaa !5
  br label %37, !llvm.loop !13

51:                                               ; preds = %37
  br label %52

52:                                               ; preds = %51
  %53 = load i32, ptr %2, align 4, !tbaa !5
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %2, align 4, !tbaa !5
  br label %5, !llvm.loop !14

55:                                               ; preds = %5
  %56 = call noalias ptr @fopen(ptr noundef @.str.3, ptr noundef @.str.4)
  %57 = icmp ne ptr %56, null
  br i1 %57, label %58, label %59

58:                                               ; preds = %55
  call void @print_array()
  br label %59

59:                                               ; preds = %58, %55
  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 = { 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 = { "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}


; 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 [2000000 x double], align 16
@b = external dso_local local_unnamed_addr global [2000000 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()
  %.pre.pre = load double, ptr getelementptr inbounds (i8, ptr @a, i64 8), align 8, !tbaa !5
  %vector.recur.init24 = insertelement <2 x double> poison, double %.pre.pre, i64 1
  %1 = load double, ptr getelementptr inbounds (i8, ptr @a, i64 15999992), align 8, !tbaa !5
  br label %vector.ph

vector.ph:                                        ; preds = %.preheader.preheader, %0
  %.01317 = phi i32 [ 0, %0 ], [ %20, %.preheader.preheader ]
  %.pre23 = load double, ptr getelementptr inbounds (i8, ptr @a, i64 16), align 16, !tbaa !5
  %vector.recur.init = insertelement <2 x double> poison, double %.pre23, 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.load26, %vector.body ]
  %vector.recur25 = phi <2 x double> [ %vector.recur.init24, %vector.ph ], [ %6, %vector.body ]
  %offset.idx = or disjoint i64 %index, 2
  %2 = or disjoint i64 %index, 3
  %3 = getelementptr inbounds [2000000 x double], ptr @a, i64 0, i64 %2
  %4 = getelementptr inbounds i8, ptr %3, i64 16
  %wide.load = load <2 x double>, ptr %3, align 8, !tbaa !5
  %wide.load26 = load <2 x double>, ptr %4, align 8, !tbaa !5
  %5 = shufflevector <2 x double> %vector.recur, <2 x double> %wide.load, <2 x i32> <i32 1, i32 2>
  %6 = shufflevector <2 x double> %wide.load, <2 x double> %wide.load26, <2 x i32> <i32 1, i32 2>
  %7 = shufflevector <2 x double> %vector.recur25, <2 x double> %5, <2 x i32> <i32 1, i32 2>
  %8 = fadd <2 x double> %7, %5
  %9 = fadd <2 x double> %wide.load, %6
  %10 = fadd <2 x double> %8, %wide.load
  %11 = fadd <2 x double> %9, %wide.load26
  %12 = fmul <2 x double> %10, <double 3.333300e-01, double 3.333300e-01>
  %13 = fmul <2 x double> %11, <double 3.333300e-01, double 3.333300e-01>
  %14 = getelementptr inbounds [2000000 x double], ptr @b, i64 0, i64 %offset.idx
  %15 = getelementptr inbounds i8, ptr %14, i64 16
  store <2 x double> %12, ptr %14, align 16, !tbaa !5
  store <2 x double> %13, ptr %15, align 16, !tbaa !5
  %index.next = add nuw i64 %index, 4
  %16 = icmp eq i64 %index.next, 1999996
  br i1 %16, label %.preheader.preheader, label %vector.body, !llvm.loop !9

.preheader.preheader:                             ; preds = %vector.body
  %vector.recur.extract27 = extractelement <2 x double> %wide.load26, i64 0
  %vector.recur.extract = extractelement <2 x double> %wide.load26, i64 1
  %17 = fadd double %vector.recur.extract27, %vector.recur.extract
  %18 = fadd double %17, %1
  %19 = fmul double %18, 3.333300e-01
  store double %19, ptr getelementptr inbounds (i8, ptr @b, i64 15999984), align 16, !tbaa !5
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(15999976) getelementptr inbounds (i8, ptr @a, i64 16), ptr noundef nonnull align 16 dereferenceable(15999976) getelementptr inbounds (i8, ptr @b, i64 16), i64 15999976, i1 false), !tbaa !5
  %20 = add nuw nsw i32 %.01317, 1
  %exitcond22.not = icmp eq i32 %20, 1000
  br i1 %exitcond22.not, label %21, label %vector.ph, !llvm.loop !13

21:                                               ; preds = %.preheader.preheader
  %22 = tail call noalias ptr @fopen(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.4)
  %.not = icmp eq ptr %22, null
  br i1 %.not, label %24, label %23

23:                                               ; preds = %21
  tail call void @print_array()
  br label %24

24:                                               ; preds = %23, %21
  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}


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