; LLVM IR from bondhugula/pluto :: examples/fdtd-1d (fdtd-1d)

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

@h = external dso_local global [1000000 x double], align 16
@e = external dso_local global [1000001 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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #2

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

9:                                                ; preds = %65, %0
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = icmp sle i32 %10, 10000
  br i1 %11, label %12, label %68

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

13:                                               ; preds = %35, %12
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = icmp sle i32 %14, 999999
  br i1 %15, label %16, label %38

16:                                               ; preds = %13
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [1000001 x double], ptr @e, i64 0, i64 %18
  %20 = load double, ptr %19, align 8, !tbaa !9
  %21 = load i32, ptr %3, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [1000000 x double], ptr @h, i64 0, i64 %22
  %24 = load double, ptr %23, align 8, !tbaa !9
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = sub nsw i32 %25, 1
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [1000000 x double], ptr @h, i64 0, i64 %27
  %29 = load double, ptr %28, align 8, !tbaa !9
  %30 = fsub double %24, %29
  %31 = call double @llvm.fmuladd.f64(double -5.000000e-01, double %30, double %20)
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [1000001 x double], ptr @e, i64 0, i64 %33
  store double %31, ptr %34, align 8, !tbaa !9
  br label %35

35:                                               ; preds = %16
  %36 = load i32, ptr %3, align 4, !tbaa !5
  %37 = add nsw i32 %36, 1
  store i32 %37, ptr %3, align 4, !tbaa !5
  br label %13, !llvm.loop !11

38:                                               ; preds = %13
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %39

39:                                               ; preds = %61, %38
  %40 = load i32, ptr %3, align 4, !tbaa !5
  %41 = icmp sle i32 %40, 999999
  br i1 %41, label %42, label %64

42:                                               ; preds = %39
  %43 = load i32, ptr %3, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [1000000 x double], ptr @h, i64 0, i64 %44
  %46 = load double, ptr %45, align 8, !tbaa !9
  %47 = load i32, ptr %3, align 4, !tbaa !5
  %48 = add nsw i32 %47, 1
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [1000001 x double], ptr @e, i64 0, i64 %49
  %51 = load double, ptr %50, align 8, !tbaa !9
  %52 = load i32, ptr %3, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [1000001 x double], ptr @e, i64 0, i64 %53
  %55 = load double, ptr %54, align 8, !tbaa !9
  %56 = fsub double %51, %55
  %57 = call double @llvm.fmuladd.f64(double 0xBFE6666666666666, double %56, double %46)
  %58 = load i32, ptr %3, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [1000000 x double], ptr @h, i64 0, i64 %59
  store double %57, ptr %60, align 8, !tbaa !9
  br label %61

61:                                               ; preds = %42
  %62 = load i32, ptr %3, align 4, !tbaa !5
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %3, align 4, !tbaa !5
  br label %39, !llvm.loop !13

64:                                               ; preds = %39
  br label %65

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

68:                                               ; preds = %9
  %69 = call noalias ptr @fopen(ptr noundef @.str.3, ptr noundef @.str.4)
  %70 = icmp ne ptr %69, null
  br i1 %70, label %71, label %72

71:                                               ; preds = %68
  call void @print_array()
  br label %72

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

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

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 = { "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 #4 = { 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"

@h = external dso_local local_unnamed_addr global [1000000 x double], align 16
@e = external dso_local local_unnamed_addr global [1000001 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: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  tail call void @init_array()
  %.pre25 = load double, ptr @e, align 16, !tbaa !5
  %vector.recur.init = insertelement <2 x double> poison, double %.pre25, i64 1
  br label %vector.ph31

vector.ph31:                                      ; preds = %middle.block, %0
  %.018 = phi i32 [ 1, %0 ], [ %36, %middle.block ]
  %.pre = load double, ptr @h, align 16, !tbaa !5
  %vector.recur.init35 = insertelement <2 x double> poison, double %.pre, i64 1
  br label %vector.body33

vector.body33:                                    ; preds = %vector.body33, %vector.ph31
  %index34 = phi i64 [ 0, %vector.ph31 ], [ %index.next41, %vector.body33 ]
  %vector.recur36 = phi <2 x double> [ %vector.recur.init35, %vector.ph31 ], [ %wide.load40, %vector.body33 ]
  %offset.idx = or disjoint i64 %index34, 1
  %1 = getelementptr inbounds [1000001 x double], ptr @e, i64 0, i64 %offset.idx
  %2 = getelementptr inbounds i8, ptr %1, i64 16
  %wide.load37 = load <2 x double>, ptr %1, align 8, !tbaa !5
  %wide.load38 = load <2 x double>, ptr %2, align 8, !tbaa !5
  %3 = getelementptr inbounds [1000000 x double], ptr @h, i64 0, i64 %offset.idx
  %4 = getelementptr inbounds i8, ptr %3, i64 16
  %wide.load39 = load <2 x double>, ptr %3, align 8, !tbaa !5
  %wide.load40 = load <2 x double>, ptr %4, align 8, !tbaa !5
  %5 = shufflevector <2 x double> %vector.recur36, <2 x double> %wide.load39, <2 x i32> <i32 1, i32 2>
  %6 = shufflevector <2 x double> %wide.load39, <2 x double> %wide.load40, <2 x i32> <i32 1, i32 2>
  %7 = fsub <2 x double> %wide.load39, %5
  %8 = fsub <2 x double> %wide.load40, %6
  %9 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %7, <2 x double> <double -5.000000e-01, double -5.000000e-01>, <2 x double> %wide.load37)
  %10 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %8, <2 x double> <double -5.000000e-01, double -5.000000e-01>, <2 x double> %wide.load38)
  store <2 x double> %9, ptr %1, align 8, !tbaa !5
  store <2 x double> %10, ptr %2, align 8, !tbaa !5
  %index.next41 = add nuw i64 %index34, 4
  %11 = icmp eq i64 %index.next41, 999996
  br i1 %11, label %vector.ph, label %vector.body33, !llvm.loop !9

vector.ph:                                        ; preds = %vector.body33
  %vector.recur.extract42 = extractelement <2 x double> %wide.load40, i64 1
  %12 = load double, ptr getelementptr inbounds (i8, ptr @e, i64 7999976), align 8, !tbaa !5
  %13 = load double, ptr getelementptr inbounds (i8, ptr @h, i64 7999976), align 8, !tbaa !5
  %14 = fsub double %13, %vector.recur.extract42
  %15 = tail call double @llvm.fmuladd.f64(double %14, double -5.000000e-01, double %12)
  store double %15, ptr getelementptr inbounds (i8, ptr @e, i64 7999976), align 8, !tbaa !5
  %16 = load double, ptr getelementptr inbounds (i8, ptr @e, i64 7999984), align 16, !tbaa !5
  %17 = load double, ptr getelementptr inbounds (i8, ptr @h, i64 7999984), align 16, !tbaa !5
  %18 = fsub double %17, %13
  %19 = tail call double @llvm.fmuladd.f64(double %18, double -5.000000e-01, double %16)
  store double %19, ptr getelementptr inbounds (i8, ptr @e, i64 7999984), align 16, !tbaa !5
  %20 = load double, ptr getelementptr inbounds (i8, ptr @e, i64 7999992), align 8, !tbaa !5
  %21 = load double, ptr getelementptr inbounds (i8, ptr @h, i64 7999992), align 8, !tbaa !5
  %22 = fsub double %21, %17
  %23 = tail call double @llvm.fmuladd.f64(double %22, double -5.000000e-01, double %20)
  store double %23, ptr getelementptr inbounds (i8, ptr @e, i64 7999992), align 8, !tbaa !5
  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.load28, %vector.body ]
  %24 = getelementptr inbounds [1000000 x double], ptr @h, i64 0, i64 %index
  %25 = getelementptr inbounds i8, ptr %24, i64 16
  %wide.load = load <2 x double>, ptr %24, align 16, !tbaa !5
  %wide.load26 = load <2 x double>, ptr %25, align 16, !tbaa !5
  %26 = or disjoint i64 %index, 1
  %27 = getelementptr inbounds [1000001 x double], ptr @e, i64 0, i64 %26
  %28 = getelementptr inbounds i8, ptr %27, i64 16
  %wide.load27 = load <2 x double>, ptr %27, align 8, !tbaa !5
  %wide.load28 = load <2 x double>, ptr %28, align 8, !tbaa !5
  %29 = shufflevector <2 x double> %vector.recur, <2 x double> %wide.load27, <2 x i32> <i32 1, i32 2>
  %30 = shufflevector <2 x double> %wide.load27, <2 x double> %wide.load28, <2 x i32> <i32 1, i32 2>
  %31 = fsub <2 x double> %wide.load27, %29
  %32 = fsub <2 x double> %wide.load28, %30
  %33 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %31, <2 x double> <double 0xBFE6666666666666, double 0xBFE6666666666666>, <2 x double> %wide.load)
  %34 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %32, <2 x double> <double 0xBFE6666666666666, double 0xBFE6666666666666>, <2 x double> %wide.load26)
  store <2 x double> %33, ptr %24, align 16, !tbaa !5
  store <2 x double> %34, ptr %25, align 16, !tbaa !5
  %index.next = add nuw i64 %index, 4
  %35 = icmp eq i64 %index.next, 1000000
  br i1 %35, label %middle.block, label %vector.body, !llvm.loop !13

middle.block:                                     ; preds = %vector.body
  %36 = add nuw nsw i32 %.018, 1
  %exitcond24.not = icmp eq i32 %36, 10001
  br i1 %exitcond24.not, label %37, label %vector.ph31, !llvm.loop !14

37:                                               ; preds = %middle.block
  %38 = tail call noalias ptr @fopen(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.4)
  %.not = icmp eq ptr %38, null
  br i1 %.not, label %40, label %39

39:                                               ; preds = %37
  tail call void @print_array()
  br label %40

40:                                               ; preds = %39, %37
  ret i32 0
}

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

; 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>) #3

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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 #3 = { 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, !11, !12}
!14 = distinct !{!14, !10}


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