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

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

@u1 = external dso_local global [6000 x double], align 16
@u2 = external dso_local global [6000 x double], align 16
@v1 = external dso_local global [6000 x double], align 16
@v2 = external dso_local global [6000 x double], align 16
@y = external dso_local global [6000 x double], align 16
@z = external dso_local global [6000 x double], align 16
@x = external dso_local global [6000 x double], align 16
@w = external dso_local global [6000 x double], align 16
@A = external dso_local global [6000 x [6000 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
  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 = %78, %0
  %4 = load i32, ptr %1, align 4, !tbaa !5
  %5 = icmp slt i32 %4, 6000
  br i1 %5, label %6, label %81

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 [6000 x double], ptr @u1, 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 = sdiv i32 %13, 6000
  %15 = sitofp i32 %14 to double
  %16 = fdiv double %15, 2.000000e+00
  %17 = load i32, ptr %1, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [6000 x double], ptr @u2, i64 0, i64 %18
  store double %16, ptr %19, align 8, !tbaa !9
  %20 = load i32, ptr %1, align 4, !tbaa !5
  %21 = add nsw i32 %20, 1
  %22 = sdiv i32 %21, 6000
  %23 = sitofp i32 %22 to double
  %24 = fdiv double %23, 4.000000e+00
  %25 = load i32, ptr %1, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [6000 x double], ptr @v1, i64 0, i64 %26
  store double %24, ptr %27, align 8, !tbaa !9
  %28 = load i32, ptr %1, align 4, !tbaa !5
  %29 = add nsw i32 %28, 1
  %30 = sdiv i32 %29, 6000
  %31 = sitofp i32 %30 to double
  %32 = fdiv double %31, 6.000000e+00
  %33 = load i32, ptr %1, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [6000 x double], ptr @v2, i64 0, i64 %34
  store double %32, ptr %35, align 8, !tbaa !9
  %36 = load i32, ptr %1, align 4, !tbaa !5
  %37 = add nsw i32 %36, 1
  %38 = sdiv i32 %37, 6000
  %39 = sitofp i32 %38 to double
  %40 = fdiv double %39, 8.000000e+00
  %41 = load i32, ptr %1, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [6000 x double], ptr @y, i64 0, i64 %42
  store double %40, ptr %43, align 8, !tbaa !9
  %44 = load i32, ptr %1, align 4, !tbaa !5
  %45 = add nsw i32 %44, 1
  %46 = sdiv i32 %45, 6000
  %47 = sitofp i32 %46 to double
  %48 = fdiv double %47, 9.000000e+00
  %49 = load i32, ptr %1, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [6000 x double], ptr @z, i64 0, i64 %50
  store double %48, ptr %51, align 8, !tbaa !9
  %52 = load i32, ptr %1, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [6000 x double], ptr @x, i64 0, i64 %53
  store double 0.000000e+00, ptr %54, align 8, !tbaa !9
  %55 = load i32, ptr %1, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [6000 x double], ptr @w, i64 0, i64 %56
  store double 0.000000e+00, ptr %57, align 8, !tbaa !9
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %58

58:                                               ; preds = %74, %6
  %59 = load i32, ptr %2, align 4, !tbaa !5
  %60 = icmp slt i32 %59, 6000
  br i1 %60, label %61, label %77

61:                                               ; preds = %58
  %62 = load i32, ptr %1, align 4, !tbaa !5
  %63 = sitofp i32 %62 to double
  %64 = load i32, ptr %2, align 4, !tbaa !5
  %65 = sitofp i32 %64 to double
  %66 = fmul double %63, %65
  %67 = fdiv double %66, 6.000000e+03
  %68 = load i32, ptr %1, align 4, !tbaa !5
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [6000 x [6000 x double]], ptr @A, i64 0, i64 %69
  %71 = load i32, ptr %2, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [6000 x double], ptr %70, i64 0, i64 %72
  store double %67, ptr %73, align 8, !tbaa !9
  br label %74

74:                                               ; preds = %61
  %75 = load i32, ptr %2, align 4, !tbaa !5
  %76 = add nsw i32 %75, 1
  store i32 %76, ptr %2, align 4, !tbaa !5
  br label %58, !llvm.loop !11

77:                                               ; preds = %58
  br label %78

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

81:                                               ; 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
}

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

@u1 = external dso_local local_unnamed_addr global [6000 x double], align 16
@u2 = external dso_local local_unnamed_addr global [6000 x double], align 16
@v1 = external dso_local local_unnamed_addr global [6000 x double], align 16
@v2 = external dso_local local_unnamed_addr global [6000 x double], align 16
@y = external dso_local local_unnamed_addr global [6000 x double], align 16
@z = external dso_local local_unnamed_addr global [6000 x double], align 16
@x = external dso_local local_unnamed_addr global [6000 x double], align 16
@w = external dso_local local_unnamed_addr global [6000 x double], align 16
@A = external dso_local local_unnamed_addr global [6000 x [6000 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(48000) @x, i8 0, i64 48000, i1 false), !tbaa !5
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(48000) @w, i8 0, i64 48000, i1 false), !tbaa !5
  br label %vector.ph

vector.ph:                                        ; preds = %0, %middle.block
  %indvars.iv26 = phi i64 [ 0, %0 ], [ %indvars.iv.next27, %middle.block ]
  %1 = trunc nuw nsw i64 %indvars.iv26 to i32
  %2 = uitofp nneg i32 %1 to double
  %3 = getelementptr inbounds [6000 x double], ptr @u1, i64 0, i64 %indvars.iv26
  store double %2, ptr %3, align 8, !tbaa !5
  %.cmp = icmp eq i64 %indvars.iv26, 5999
  %4 = uitofp i1 %.cmp to double
  %5 = fmul double %4, 5.000000e-01
  %6 = getelementptr inbounds [6000 x double], ptr @u2, i64 0, i64 %indvars.iv26
  store double %5, ptr %6, align 8, !tbaa !5
  %7 = fmul double %4, 2.500000e-01
  %8 = getelementptr inbounds [6000 x double], ptr @v1, i64 0, i64 %indvars.iv26
  store double %7, ptr %8, align 8, !tbaa !5
  %9 = fdiv double %4, 6.000000e+00
  %10 = getelementptr inbounds [6000 x double], ptr @v2, i64 0, i64 %indvars.iv26
  store double %9, ptr %10, align 8, !tbaa !5
  %11 = fmul double %4, 1.250000e-01
  %12 = getelementptr inbounds [6000 x double], ptr @y, i64 0, i64 %indvars.iv26
  store double %11, ptr %12, align 8, !tbaa !5
  %13 = fdiv double %4, 9.000000e+00
  %14 = getelementptr inbounds [6000 x double], ptr @z, i64 0, i64 %indvars.iv26
  store double %13, ptr %14, align 8, !tbaa !5
  %broadcast.splatinsert = insertelement <2 x i64> poison, i64 %indvars.iv26, 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, %vector.body ]
  %vec.ind = phi <2 x i64> [ <i64 0, i64 1>, %vector.ph ], [ %vec.ind.next, %vector.body ]
  %15 = mul nuw nsw <2 x i64> %vec.ind, %broadcast.splat
  %16 = trunc <2 x i64> %15 to <2 x i32>
  %17 = uitofp <2 x i32> %16 to <2 x double>
  %18 = fdiv <2 x double> %17, <double 6.000000e+03, double 6.000000e+03>
  %19 = getelementptr inbounds [6000 x [6000 x double]], ptr @A, i64 0, i64 %indvars.iv26, i64 %index
  store <2 x double> %18, ptr %19, align 16, !tbaa !5
  %index.next = add nuw i64 %index, 2
  %vec.ind.next = add <2 x i64> %vec.ind, <i64 2, i64 2>
  %20 = icmp eq i64 %index.next, 6000
  br i1 %20, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %indvars.iv.next27 = add nuw nsw i64 %indvars.iv26, 1
  %exitcond29.not = icmp eq i64 %indvars.iv.next27, 6000
  br i1 %exitcond29.not, label %21, label %vector.ph, !llvm.loop !13

21:                                               ; 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: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LoopIdiomRecognizePass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass