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

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

@y_1 = external dso_local global [10017 x double], align 16
@y_2 = external dso_local global [10019 x double], align 16
@x1 = external dso_local global [10023 x double], align 16
@x2 = external dso_local global [10031 x double], align 16
@a = external dso_local global [10000 x [10000 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 = %43, %0
  %4 = load i32, ptr %1, align 4, !tbaa !5
  %5 = icmp slt i32 %4, 10000
  br i1 %5, label %6, label %46

6:                                                ; preds = %3
  %7 = load i32, ptr %1, align 4, !tbaa !5
  %8 = sitofp i32 %7 to double
  %9 = load i32, ptr %1, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [10017 x double], ptr @y_1, i64 0, i64 %10
  store double %8, ptr %11, align 8, !tbaa !9
  %12 = load i32, ptr %1, align 4, !tbaa !5
  %13 = add nsw i32 %12, 1
  %14 = sitofp i32 %13 to double
  %15 = load i32, ptr %1, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [10019 x double], ptr @y_2, i64 0, i64 %16
  store double %14, ptr %17, align 8, !tbaa !9
  %18 = load i32, ptr %1, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [10023 x double], ptr @x1, i64 0, i64 %19
  store double 0.000000e+00, ptr %20, align 8, !tbaa !9
  %21 = load i32, ptr %1, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [10031 x double], ptr @x2, i64 0, i64 %22
  store double 0.000000e+00, ptr %23, align 8, !tbaa !9
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %39, %6
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = icmp slt i32 %25, 10000
  br i1 %26, label %27, label %42

27:                                               ; preds = %24
  %28 = load i32, ptr %1, align 4, !tbaa !5
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %30 = add nsw i32 %28, %29
  %31 = sitofp i32 %30 to double
  %32 = fadd double %31, 1.000000e+00
  %33 = load i32, ptr %1, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [10000 x [10000 x double]], ptr @a, i64 0, i64 %34
  %36 = load i32, ptr %2, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [10000 x double], ptr %35, i64 0, i64 %37
  store double %32, ptr %38, align 8, !tbaa !9
  br label %39

39:                                               ; preds = %27
  %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 %24, !llvm.loop !11

42:                                               ; preds = %24
  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 %3, !llvm.loop !13

46:                                               ; preds = %3
  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}


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

@y_1 = external dso_local local_unnamed_addr global [10017 x double], align 16
@y_2 = external dso_local local_unnamed_addr global [10019 x double], align 16
@x1 = external dso_local local_unnamed_addr global [10023 x double], align 16
@x2 = external dso_local local_unnamed_addr global [10031 x double], align 16
@a = external dso_local local_unnamed_addr global [10000 x [10000 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 {
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(80000) @x1, i8 0, i64 80000, i1 false), !tbaa !5
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(80000) @x2, i8 0, i64 80000, i1 false), !tbaa !5
  br label %vector.ph

vector.ph:                                        ; preds = %0, %middle.block
  %indvars.iv18 = phi i64 [ 0, %0 ], [ %indvars.iv.next19, %middle.block ]
  %1 = trunc nuw nsw i64 %indvars.iv18 to i32
  %2 = uitofp nneg i32 %1 to double
  %3 = getelementptr inbounds [10017 x double], ptr @y_1, i64 0, i64 %indvars.iv18
  store double %2, ptr %3, align 8, !tbaa !5
  %indvars.iv.next19 = add nuw nsw i64 %indvars.iv18, 1
  %4 = trunc nuw nsw i64 %indvars.iv.next19 to i32
  %5 = uitofp nneg i32 %4 to double
  %6 = getelementptr inbounds [10019 x double], ptr @y_2, i64 0, i64 %indvars.iv18
  store double %5, ptr %6, align 8, !tbaa !5
  %broadcast.splatinsert = insertelement <2 x i64> poison, i64 %indvars.iv.next19, i64 0
  %broadcast.splat = shufflevector <2 x i64> %broadcast.splatinsert, <2 x i64> poison, <2 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next.1, %vector.body ]
  %vec.ind = phi <2 x i64> [ <i64 0, i64 1>, %vector.ph ], [ %vec.ind.next.1, %vector.body ]
  %step.add = add <2 x i64> %vec.ind, <i64 2, i64 2>
  %7 = add nuw nsw <2 x i64> %broadcast.splat, %vec.ind
  %8 = add nuw nsw <2 x i64> %broadcast.splat, %step.add
  %9 = trunc <2 x i64> %7 to <2 x i32>
  %10 = trunc <2 x i64> %8 to <2 x i32>
  %11 = uitofp <2 x i32> %9 to <2 x double>
  %12 = uitofp <2 x i32> %10 to <2 x double>
  %13 = getelementptr inbounds [10000 x [10000 x double]], ptr @a, i64 0, i64 %indvars.iv18, i64 %index
  %14 = getelementptr inbounds i8, ptr %13, i64 16
  store <2 x double> %11, ptr %13, align 16, !tbaa !5
  store <2 x double> %12, ptr %14, align 16, !tbaa !5
  %index.next = or disjoint i64 %index, 4
  %vec.ind.next = add <2 x i64> %vec.ind, <i64 4, i64 4>
  %step.add.1 = add <2 x i64> %vec.ind, <i64 6, i64 6>
  %15 = add nuw nsw <2 x i64> %broadcast.splat, %vec.ind.next
  %16 = add nuw nsw <2 x i64> %broadcast.splat, %step.add.1
  %17 = trunc <2 x i64> %15 to <2 x i32>
  %18 = trunc <2 x i64> %16 to <2 x i32>
  %19 = uitofp <2 x i32> %17 to <2 x double>
  %20 = uitofp <2 x i32> %18 to <2 x double>
  %21 = getelementptr inbounds [10000 x [10000 x double]], ptr @a, i64 0, i64 %indvars.iv18, i64 %index.next
  %22 = getelementptr inbounds i8, ptr %21, i64 16
  store <2 x double> %19, ptr %21, align 16, !tbaa !5
  store <2 x double> %20, ptr %22, align 16, !tbaa !5
  %index.next.1 = add nuw nsw i64 %index, 8
  %vec.ind.next.1 = add <2 x i64> %vec.ind, <i64 8, i64 8>
  %23 = icmp eq i64 %index.next.1, 10000
  br i1 %23, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %exitcond21.not = icmp eq i64 %indvars.iv.next19, 10000
  br i1 %exitcond21.not, label %24, label %vector.ph, !llvm.loop !13

24:                                               ; preds = %middle.block
  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"}
!13 = distinct !{!13, !10}


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