; LLVM IR from bondhugula/pluto :: examples/fdtd-2d (fdtd-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"

@ey = external dso_local global [2049 x [2048 x double]], align 16
@ex = external dso_local global [2048 x [2049 x double]], align 16
@hz = external dso_local global [2048 x [2048 x double]], align 16

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

3:                                                ; preds = %21, %0
  %4 = load i32, ptr %1, align 4, !tbaa !5
  %5 = icmp slt i32 %4, 2049
  br i1 %5, label %6, label %24

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

7:                                                ; preds = %17, %6
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = icmp slt i32 %8, 2048
  br i1 %9, label %10, label %20

10:                                               ; preds = %7
  %11 = load i32, ptr %1, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [2049 x [2048 x double]], ptr @ey, i64 0, i64 %12
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [2048 x double], ptr %13, i64 0, i64 %15
  store double 0.000000e+00, ptr %16, align 8, !tbaa !9
  br label %17

17:                                               ; preds = %10
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = add nsw i32 %18, 1
  store i32 %19, ptr %2, align 4, !tbaa !5
  br label %7, !llvm.loop !11

20:                                               ; preds = %7
  br label %21

21:                                               ; preds = %20
  %22 = load i32, ptr %1, align 4, !tbaa !5
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr %1, align 4, !tbaa !5
  br label %3, !llvm.loop !13

24:                                               ; preds = %3
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %25

25:                                               ; preds = %43, %24
  %26 = load i32, ptr %1, align 4, !tbaa !5
  %27 = icmp slt i32 %26, 2048
  br i1 %27, label %28, label %46

28:                                               ; preds = %25
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %39, %28
  %30 = load i32, ptr %2, align 4, !tbaa !5
  %31 = icmp slt i32 %30, 2049
  br i1 %31, label %32, label %42

32:                                               ; preds = %29
  %33 = load i32, ptr %1, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [2048 x [2049 x double]], ptr @ex, i64 0, i64 %34
  %36 = load i32, ptr %2, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [2049 x double], ptr %35, i64 0, i64 %37
  store double 0.000000e+00, ptr %38, align 8, !tbaa !9
  br label %39

39:                                               ; preds = %32
  %40 = load i32, ptr %2, align 4, !tbaa !5
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %2, align 4, !tbaa !5
  br label %29, !llvm.loop !14

42:                                               ; preds = %29
  br label %43

43:                                               ; preds = %42
  %44 = load i32, ptr %1, align 4, !tbaa !5
  %45 = add nsw i32 %44, 1
  store i32 %45, ptr %1, align 4, !tbaa !5
  br label %25, !llvm.loop !15

46:                                               ; preds = %25
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %47

47:                                               ; preds = %57, %46
  %48 = load i32, ptr %2, align 4, !tbaa !5
  %49 = icmp slt i32 %48, 2048
  br i1 %49, label %50, label %60

50:                                               ; preds = %47
  %51 = load i32, ptr %2, align 4, !tbaa !5
  %52 = sitofp i32 %51 to double
  %53 = fdiv double %52, 2.048000e+03
  %54 = load i32, ptr %2, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [2048 x double], ptr @ey, i64 0, i64 %55
  store double %53, ptr %56, align 8, !tbaa !9
  br label %57

57:                                               ; preds = %50
  %58 = load i32, ptr %2, align 4, !tbaa !5
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %2, align 4, !tbaa !5
  br label %47, !llvm.loop !16

60:                                               ; preds = %47
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %61

61:                                               ; preds = %79, %60
  %62 = load i32, ptr %1, align 4, !tbaa !5
  %63 = icmp slt i32 %62, 2048
  br i1 %63, label %64, label %82

64:                                               ; preds = %61
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %65

65:                                               ; preds = %75, %64
  %66 = load i32, ptr %2, align 4, !tbaa !5
  %67 = icmp slt i32 %66, 2048
  br i1 %67, label %68, label %78

68:                                               ; preds = %65
  %69 = load i32, ptr %1, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [2048 x [2048 x double]], ptr @hz, i64 0, i64 %70
  %72 = load i32, ptr %2, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [2048 x double], ptr %71, i64 0, i64 %73
  store double 0.000000e+00, ptr %74, align 8, !tbaa !9
  br label %75

75:                                               ; preds = %68
  %76 = load i32, ptr %2, align 4, !tbaa !5
  %77 = add nsw i32 %76, 1
  store i32 %77, ptr %2, align 4, !tbaa !5
  br label %65, !llvm.loop !17

78:                                               ; preds = %65
  br label %79

79:                                               ; preds = %78
  %80 = load i32, ptr %1, align 4, !tbaa !5
  %81 = add nsw i32 %80, 1
  store i32 %81, ptr %1, align 4, !tbaa !5
  br label %61, !llvm.loop !18

82:                                               ; preds = %61
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  ret void
}

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 = { 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}
!17 = distinct !{!17, !12}
!18 = distinct !{!18, !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"

@ey = external dso_local local_unnamed_addr global [2049 x [2048 x double]], align 16
@ex = external dso_local local_unnamed_addr global [2048 x [2049 x double]], align 16
@hz = external dso_local local_unnamed_addr global [2048 x [2048 x double]], align 16

; Function Attrs: nofree norecurse nosync nounwind memory(write, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @init_array() local_unnamed_addr #0 {
.preheader27.preheader:
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(33570816) @ey, i8 0, i64 33570816, i1 false), !tbaa !5
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(33570816) @ex, i8 0, i64 33570816, i1 false), !tbaa !5
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %.preheader27.preheader
  %index = phi i64 [ 0, %.preheader27.preheader ], [ %index.next.1, %vector.body ]
  %vec.ind = phi <2 x i32> [ <i32 0, i32 1>, %.preheader27.preheader ], [ %vec.ind.next.1, %vector.body ]
  %step.add = add <2 x i32> %vec.ind, <i32 2, i32 2>
  %0 = uitofp <2 x i32> %vec.ind to <2 x double>
  %1 = uitofp <2 x i32> %step.add to <2 x double>
  %2 = fmul <2 x double> %0, <double 0x3F40000000000000, double 0x3F40000000000000>
  %3 = fmul <2 x double> %1, <double 0x3F40000000000000, double 0x3F40000000000000>
  %4 = getelementptr inbounds [2048 x double], ptr @ey, i64 0, i64 %index
  %5 = getelementptr inbounds i8, ptr %4, i64 16
  store <2 x double> %2, ptr %4, align 16, !tbaa !5
  store <2 x double> %3, ptr %5, align 16, !tbaa !5
  %index.next = or disjoint i64 %index, 4
  %vec.ind.next = add <2 x i32> %vec.ind, <i32 4, i32 4>
  %step.add.1 = add <2 x i32> %vec.ind, <i32 6, i32 6>
  %6 = uitofp <2 x i32> %vec.ind.next to <2 x double>
  %7 = uitofp <2 x i32> %step.add.1 to <2 x double>
  %8 = fmul <2 x double> %6, <double 0x3F40000000000000, double 0x3F40000000000000>
  %9 = fmul <2 x double> %7, <double 0x3F40000000000000, double 0x3F40000000000000>
  %10 = getelementptr inbounds [2048 x double], ptr @ey, i64 0, i64 %index.next
  %11 = getelementptr inbounds i8, ptr %10, i64 16
  store <2 x double> %8, ptr %10, align 16, !tbaa !5
  store <2 x double> %9, ptr %11, align 16, !tbaa !5
  %index.next.1 = add nuw nsw i64 %index, 8
  %vec.ind.next.1 = add <2 x i32> %vec.ind, <i32 8, i32 8>
  %12 = icmp eq i64 %index.next.1, 2048
  br i1 %12, label %.preheader.preheader, label %vector.body, !llvm.loop !9

.preheader.preheader:                             ; preds = %vector.body
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(33554432) @hz, i8 0, i64 33554432, i1 false), !tbaa !5
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

attributes #0 = { nofree norecurse nosync nounwind memory(write, 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }

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


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