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

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

@data = external dso_local global [1501 x [1501 x double]], align 16

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

5:                                                ; preds = %32, %0
  %6 = load i32, ptr %1, align 4, !tbaa !5
  %7 = load i32, ptr %3, align 4, !tbaa !5
  %8 = icmp sle i32 %6, %7
  br i1 %8, label %9, label %35

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

10:                                               ; preds = %28, %9
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = load i32, ptr %4, align 4, !tbaa !5
  %13 = icmp sle i32 %11, %12
  br i1 %13, label %14, label %31

14:                                               ; preds = %10
  %15 = load i32, ptr %1, align 4, !tbaa !5
  %16 = sitofp i32 %15 to float
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = sitofp i32 %17 to float
  %19 = fmul float %16, %18
  %20 = fdiv float %19, 1.500000e+03
  %21 = fpext float %20 to double
  %22 = load i32, ptr %1, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [1501 x [1501 x double]], ptr @data, i64 0, i64 %23
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [1501 x double], ptr %24, i64 0, i64 %26
  store double %21, ptr %27, align 8, !tbaa !9
  br label %28

28:                                               ; preds = %14
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr %2, align 4, !tbaa !5
  br label %10, !llvm.loop !11

31:                                               ; preds = %10
  br label %32

32:                                               ; preds = %31
  %33 = load i32, ptr %1, align 4, !tbaa !5
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %1, align 4, !tbaa !5
  br label %5, !llvm.loop !13

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

; 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

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 = { 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}


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

@data = external dso_local local_unnamed_addr global [1501 x [1501 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 {
  br label %.preheader

.preheader:                                       ; preds = %0, %scalar.ph
  %indvars.iv14 = phi i64 [ 0, %0 ], [ %indvars.iv.next15, %scalar.ph ]
  %1 = trunc nuw nsw i64 %indvars.iv14 to i32
  %2 = uitofp nneg i32 %1 to float
  %broadcast.splatinsert = insertelement <2 x float> poison, float %2, i64 0
  %broadcast.splat = shufflevector <2 x float> %broadcast.splatinsert, <2 x float> poison, <2 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %.preheader
  %index = phi i64 [ 0, %.preheader ], [ %index.next.1, %vector.body ]
  %vec.ind = phi <2 x i32> [ <i32 0, i32 1>, %.preheader ], [ %vec.ind.next.1, %vector.body ]
  %3 = uitofp <2 x i32> %vec.ind to <2 x float>
  %4 = fmul <2 x float> %broadcast.splat, %3
  %5 = fdiv <2 x float> %4, <float 1.500000e+03, float 1.500000e+03>
  %6 = fpext <2 x float> %5 to <2 x double>
  %7 = getelementptr inbounds [1501 x [1501 x double]], ptr @data, i64 0, i64 %indvars.iv14, i64 %index
  store <2 x double> %6, ptr %7, align 8, !tbaa !5
  %index.next = or disjoint i64 %index, 2
  %vec.ind.next = add <2 x i32> %vec.ind, <i32 2, i32 2>
  %8 = uitofp <2 x i32> %vec.ind.next to <2 x float>
  %9 = fmul <2 x float> %broadcast.splat, %8
  %10 = fdiv <2 x float> %9, <float 1.500000e+03, float 1.500000e+03>
  %11 = fpext <2 x float> %10 to <2 x double>
  %12 = getelementptr inbounds [1501 x [1501 x double]], ptr @data, i64 0, i64 %indvars.iv14, i64 %index.next
  store <2 x double> %11, ptr %12, align 8, !tbaa !5
  %index.next.1 = add nuw nsw i64 %index, 4
  %vec.ind.next.1 = add <2 x i32> %vec.ind, <i32 4, i32 4>
  %13 = icmp eq i64 %index.next.1, 1500
  br i1 %13, label %scalar.ph, label %vector.body, !llvm.loop !9

scalar.ph:                                        ; preds = %vector.body
  %14 = fmul float %2, 1.500000e+03
  %15 = fdiv float %14, 1.500000e+03
  %16 = fpext float %15 to double
  %17 = getelementptr inbounds [1501 x [1501 x double]], ptr @data, i64 0, i64 %indvars.iv14, i64 1500
  store double %16, ptr %17, align 8, !tbaa !5
  %indvars.iv.next15 = add nuw nsw i64 %indvars.iv14, 1
  %exitcond17.not = icmp eq i64 %indvars.iv.next15, 1501
  br i1 %exitcond17.not, label %18, label %.preheader, !llvm.loop !13

18:                                               ; preds = %scalar.ph
  ret void
}

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

!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: GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass