; LLVM IR from bondhugula/pluto :: examples/seidel (seidel)

; 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
@.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 i32, align 4
  %6 = alloca double, align 8
  %7 = 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 4, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @init_array()
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %118, %0
  %9 = load i32, ptr %5, align 4, !tbaa !5
  %10 = icmp sle i32 %9, 199
  br i1 %10, label %11, label %121

11:                                               ; preds = %8
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %114, %11
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = icmp sle i32 %13, 1998
  br i1 %14, label %15, label %117

15:                                               ; preds = %12
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %110, %15
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = icmp sle i32 %17, 1998
  br i1 %18, label %19, label %113

19:                                               ; preds = %16
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = sub nsw i32 %20, 1
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [2000 x [2000 x double]], ptr @a, i64 0, i64 %22
  %24 = load i32, ptr %3, align 4, !tbaa !5
  %25 = sub nsw i32 %24, 1
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [2000 x double], ptr %23, i64 0, i64 %26
  %28 = load double, ptr %27, align 8, !tbaa !9
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %30 = sub nsw i32 %29, 1
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [2000 x [2000 x double]], ptr @a, i64 0, i64 %31
  %33 = load i32, ptr %3, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [2000 x double], ptr %32, i64 0, i64 %34
  %36 = load double, ptr %35, align 8, !tbaa !9
  %37 = fadd double %28, %36
  %38 = load i32, ptr %2, align 4, !tbaa !5
  %39 = sub nsw i32 %38, 1
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [2000 x [2000 x double]], ptr @a, i64 0, i64 %40
  %42 = load i32, ptr %3, align 4, !tbaa !5
  %43 = add nsw i32 %42, 1
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [2000 x double], ptr %41, i64 0, i64 %44
  %46 = load double, ptr %45, align 8, !tbaa !9
  %47 = fadd double %37, %46
  %48 = load i32, ptr %2, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [2000 x [2000 x double]], ptr @a, i64 0, i64 %49
  %51 = load i32, ptr %3, align 4, !tbaa !5
  %52 = sub nsw i32 %51, 1
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [2000 x double], ptr %50, i64 0, i64 %53
  %55 = load double, ptr %54, align 8, !tbaa !9
  %56 = fadd double %47, %55
  %57 = load i32, ptr %2, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [2000 x [2000 x double]], ptr @a, i64 0, i64 %58
  %60 = load i32, ptr %3, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [2000 x double], ptr %59, i64 0, i64 %61
  %63 = load double, ptr %62, align 8, !tbaa !9
  %64 = fadd double %56, %63
  %65 = load i32, ptr %2, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [2000 x [2000 x double]], ptr @a, i64 0, i64 %66
  %68 = load i32, ptr %3, align 4, !tbaa !5
  %69 = add nsw i32 %68, 1
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [2000 x double], ptr %67, i64 0, i64 %70
  %72 = load double, ptr %71, align 8, !tbaa !9
  %73 = fadd double %64, %72
  %74 = load i32, ptr %2, align 4, !tbaa !5
  %75 = add nsw i32 %74, 1
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [2000 x [2000 x double]], ptr @a, i64 0, i64 %76
  %78 = load i32, ptr %3, align 4, !tbaa !5
  %79 = sub nsw i32 %78, 1
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [2000 x double], ptr %77, i64 0, i64 %80
  %82 = load double, ptr %81, align 8, !tbaa !9
  %83 = fadd double %73, %82
  %84 = load i32, ptr %2, align 4, !tbaa !5
  %85 = add nsw i32 %84, 1
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds [2000 x [2000 x double]], ptr @a, i64 0, i64 %86
  %88 = load i32, ptr %3, 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 = fadd double %83, %91
  %93 = load i32, ptr %2, align 4, !tbaa !5
  %94 = add nsw i32 %93, 1
  %95 = sext i32 %94 to i64
  %96 = getelementptr inbounds [2000 x [2000 x double]], ptr @a, i64 0, i64 %95
  %97 = load i32, ptr %3, align 4, !tbaa !5
  %98 = add nsw i32 %97, 1
  %99 = sext i32 %98 to i64
  %100 = getelementptr inbounds [2000 x double], ptr %96, i64 0, i64 %99
  %101 = load double, ptr %100, align 8, !tbaa !9
  %102 = fadd double %92, %101
  %103 = fdiv double %102, 9.000000e+00
  %104 = load i32, ptr %2, align 4, !tbaa !5
  %105 = sext i32 %104 to i64
  %106 = getelementptr inbounds [2000 x [2000 x double]], ptr @a, i64 0, i64 %105
  %107 = load i32, ptr %3, align 4, !tbaa !5
  %108 = sext i32 %107 to i64
  %109 = getelementptr inbounds [2000 x double], ptr %106, i64 0, i64 %108
  store double %103, ptr %109, align 8, !tbaa !9
  br label %110

110:                                              ; preds = %19
  %111 = load i32, ptr %3, align 4, !tbaa !5
  %112 = add nsw i32 %111, 1
  store i32 %112, ptr %3, align 4, !tbaa !5
  br label %16, !llvm.loop !11

113:                                              ; preds = %16
  br label %114

114:                                              ; preds = %113
  %115 = load i32, ptr %2, align 4, !tbaa !5
  %116 = add nsw i32 %115, 1
  store i32 %116, ptr %2, align 4, !tbaa !5
  br label %12, !llvm.loop !13

117:                                              ; preds = %12
  br label %118

118:                                              ; preds = %117
  %119 = load i32, ptr %5, align 4, !tbaa !5
  %120 = add nsw i32 %119, 1
  store i32 %120, ptr %5, align 4, !tbaa !5
  br label %8, !llvm.loop !14

121:                                              ; preds = %8
  %122 = call noalias ptr @fopen(ptr noundef @.str.3, ptr noundef @.str.4)
  %123 = icmp ne ptr %122, null
  br i1 %123, label %124, label %125

124:                                              ; preds = %121
  call void @print_array()
  br label %125

125:                                              ; preds = %124, %121
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, 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}


; 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
@.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 %.preheader28

.preheader28:                                     ; preds = %0, %26
  %.02731 = phi i32 [ 0, %0 ], [ %27, %26 ]
  %.pre.pre = load double, ptr @a, align 16, !tbaa !5
  br label %.preheader

.preheader:                                       ; preds = %.preheader28, %25
  %.pre = phi double [ %.pre.pre, %.preheader28 ], [ %.pre41, %25 ]
  %indvars.iv33 = phi i64 [ 1, %.preheader28 ], [ %indvars.iv.next34, %25 ]
  %1 = add nsw i64 %indvars.iv33, -1
  %indvars.iv.next34 = add nuw nsw i64 %indvars.iv33, 1
  %.phi.trans.insert38 = getelementptr inbounds [2000 x [2000 x double]], ptr @a, i64 0, i64 %1, i64 1
  %.pre39 = load double, ptr %.phi.trans.insert38, align 8, !tbaa !5
  %.phi.trans.insert40 = getelementptr inbounds [2000 x [2000 x double]], ptr @a, i64 0, i64 %indvars.iv33, i64 0
  %.pre41 = load double, ptr %.phi.trans.insert40, align 16, !tbaa !5
  %.phi.trans.insert42 = getelementptr inbounds [2000 x [2000 x double]], ptr @a, i64 0, i64 %indvars.iv33, i64 1
  %.pre43 = load double, ptr %.phi.trans.insert42, align 8, !tbaa !5
  %.phi.trans.insert44 = getelementptr inbounds [2000 x [2000 x double]], ptr @a, i64 0, i64 %indvars.iv.next34, i64 0
  %.pre45 = load double, ptr %.phi.trans.insert44, align 16, !tbaa !5
  %.phi.trans.insert46 = getelementptr inbounds [2000 x [2000 x double]], ptr @a, i64 0, i64 %indvars.iv.next34, i64 1
  %.pre47 = load double, ptr %.phi.trans.insert46, align 8, !tbaa !5
  br label %2

2:                                                ; preds = %.preheader, %2
  %3 = phi double [ %.pre47, %.preheader ], [ %22, %2 ]
  %4 = phi double [ %.pre45, %.preheader ], [ %3, %2 ]
  %5 = phi double [ %.pre43, %.preheader ], [ %17, %2 ]
  %6 = phi double [ %.pre41, %.preheader ], [ %24, %2 ]
  %7 = phi double [ %.pre39, %.preheader ], [ %11, %2 ]
  %8 = phi double [ %.pre, %.preheader ], [ %7, %2 ]
  %indvars.iv = phi i64 [ 1, %.preheader ], [ %indvars.iv.next, %2 ]
  %9 = fadd double %8, %7
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %10 = getelementptr inbounds [2000 x [2000 x double]], ptr @a, i64 0, i64 %1, i64 %indvars.iv.next
  %11 = load double, ptr %10, align 8, !tbaa !5
  %12 = fadd double %9, %11
  %13 = fadd double %12, %6
  %14 = getelementptr inbounds [2000 x [2000 x double]], ptr @a, i64 0, i64 %indvars.iv33, i64 %indvars.iv
  %15 = fadd double %13, %5
  %16 = getelementptr inbounds [2000 x [2000 x double]], ptr @a, i64 0, i64 %indvars.iv33, i64 %indvars.iv.next
  %17 = load double, ptr %16, align 8, !tbaa !5
  %18 = fadd double %15, %17
  %19 = fadd double %18, %4
  %20 = fadd double %19, %3
  %21 = getelementptr inbounds [2000 x [2000 x double]], ptr @a, i64 0, i64 %indvars.iv.next34, i64 %indvars.iv.next
  %22 = load double, ptr %21, align 8, !tbaa !5
  %23 = fadd double %20, %22
  %24 = fdiv double %23, 9.000000e+00
  store double %24, ptr %14, align 8, !tbaa !5
  %exitcond.not = icmp eq i64 %indvars.iv.next, 1999
  br i1 %exitcond.not, label %25, label %2, !llvm.loop !9

25:                                               ; preds = %2
  %exitcond36.not = icmp eq i64 %indvars.iv.next34, 1999
  br i1 %exitcond36.not, label %26, label %.preheader, !llvm.loop !11

26:                                               ; preds = %25
  %27 = add nuw nsw i32 %.02731, 1
  %exitcond37.not = icmp eq i32 %27, 200
  br i1 %exitcond37.not, label %28, label %.preheader28, !llvm.loop !12

28:                                               ; preds = %26
  %29 = tail call noalias ptr @fopen(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.4)
  %.not = icmp eq ptr %29, null
  br i1 %.not, label %31, label %30

30:                                               ; preds = %28
  tail call void @print_array()
  br label %31

31:                                               ; preds = %30, %28
  ret i32 0
}

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #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 = { 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" }

!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}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


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