; LLVM IR from pmla/polyhedral-template-matching :: ptm_polar.ll (ZN3ptm12InnerProductEPdiPA3_KdPA3_dPa)

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #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: mustprogress nounwind uwtable
define dso_local void @_ZN3ptm12InnerProductEPdiPA3_KdPA3_dPa(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #2 {
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca double, align 8
  %13 = alloca double, align 8
  %14 = alloca double, align 8
  %15 = alloca double, align 8
  %16 = alloca double, align 8
  %17 = alloca double, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  store ptr %4, ptr %10, align 8, !tbaa !5
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = getelementptr inbounds double, ptr %18, i64 8
  store double 0.000000e+00, ptr %19, align 8, !tbaa !11
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds double, ptr %20, i64 7
  store double 0.000000e+00, ptr %21, align 8, !tbaa !11
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = getelementptr inbounds double, ptr %22, i64 6
  store double 0.000000e+00, ptr %23, align 8, !tbaa !11
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds double, ptr %24, i64 5
  store double 0.000000e+00, ptr %25, align 8, !tbaa !11
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = getelementptr inbounds double, ptr %26, i64 4
  store double 0.000000e+00, ptr %27, align 8, !tbaa !11
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds double, ptr %28, i64 3
  store double 0.000000e+00, ptr %29, align 8, !tbaa !11
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds double, ptr %30, i64 2
  store double 0.000000e+00, ptr %31, align 8, !tbaa !11
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds double, ptr %32, i64 1
  store double 0.000000e+00, ptr %33, align 8, !tbaa !11
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds double, ptr %34, i64 0
  store double 0.000000e+00, ptr %35, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %36

36:                                               ; preds = %144, %5
  %37 = load i32, ptr %11, align 4, !tbaa !9
  %38 = load i32, ptr %7, align 4, !tbaa !9
  %39 = icmp slt i32 %37, %38
  br i1 %39, label %41, label %40

40:                                               ; preds = %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %147

41:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %42 = load ptr, ptr %8, align 8, !tbaa !5
  %43 = load i32, ptr %11, align 4, !tbaa !9
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [3 x double], ptr %42, i64 %44
  %46 = getelementptr inbounds [3 x double], ptr %45, i64 0, i64 0
  %47 = load double, ptr %46, align 8, !tbaa !11
  store double %47, ptr %12, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  %49 = load i32, ptr %11, align 4, !tbaa !9
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [3 x double], ptr %48, i64 %50
  %52 = getelementptr inbounds [3 x double], ptr %51, i64 0, i64 1
  %53 = load double, ptr %52, align 8, !tbaa !11
  store double %53, ptr %13, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  %55 = load i32, ptr %11, align 4, !tbaa !9
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [3 x double], ptr %54, i64 %56
  %58 = getelementptr inbounds [3 x double], ptr %57, i64 0, i64 2
  %59 = load double, ptr %58, align 8, !tbaa !11
  store double %59, ptr %14, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  %60 = load ptr, ptr %9, align 8, !tbaa !5
  %61 = load ptr, ptr %10, align 8, !tbaa !5
  %62 = load i32, ptr %11, align 4, !tbaa !9
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds i8, ptr %61, i64 %63
  %65 = load i8, ptr %64, align 1, !tbaa !13
  %66 = sext i8 %65 to i64
  %67 = getelementptr inbounds [3 x double], ptr %60, i64 %66
  %68 = getelementptr inbounds [3 x double], ptr %67, i64 0, i64 0
  %69 = load double, ptr %68, align 8, !tbaa !11
  store double %69, ptr %15, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  %70 = load ptr, ptr %9, align 8, !tbaa !5
  %71 = load ptr, ptr %10, align 8, !tbaa !5
  %72 = load i32, ptr %11, align 4, !tbaa !9
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds i8, ptr %71, i64 %73
  %75 = load i8, ptr %74, align 1, !tbaa !13
  %76 = sext i8 %75 to i64
  %77 = getelementptr inbounds [3 x double], ptr %70, i64 %76
  %78 = getelementptr inbounds [3 x double], ptr %77, i64 0, i64 1
  %79 = load double, ptr %78, align 8, !tbaa !11
  store double %79, ptr %16, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #3
  %80 = load ptr, ptr %9, align 8, !tbaa !5
  %81 = load ptr, ptr %10, align 8, !tbaa !5
  %82 = load i32, ptr %11, align 4, !tbaa !9
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds i8, ptr %81, i64 %83
  %85 = load i8, ptr %84, align 1, !tbaa !13
  %86 = sext i8 %85 to i64
  %87 = getelementptr inbounds [3 x double], ptr %80, i64 %86
  %88 = getelementptr inbounds [3 x double], ptr %87, i64 0, i64 2
  %89 = load double, ptr %88, align 8, !tbaa !11
  store double %89, ptr %17, align 8, !tbaa !11
  %90 = load double, ptr %12, align 8, !tbaa !11
  %91 = load double, ptr %15, align 8, !tbaa !11
  %92 = load ptr, ptr %6, align 8, !tbaa !5
  %93 = getelementptr inbounds double, ptr %92, i64 0
  %94 = load double, ptr %93, align 8, !tbaa !11
  %95 = call double @llvm.fmuladd.f64(double %90, double %91, double %94)
  store double %95, ptr %93, align 8, !tbaa !11
  %96 = load double, ptr %12, align 8, !tbaa !11
  %97 = load double, ptr %16, align 8, !tbaa !11
  %98 = load ptr, ptr %6, align 8, !tbaa !5
  %99 = getelementptr inbounds double, ptr %98, i64 1
  %100 = load double, ptr %99, align 8, !tbaa !11
  %101 = call double @llvm.fmuladd.f64(double %96, double %97, double %100)
  store double %101, ptr %99, align 8, !tbaa !11
  %102 = load double, ptr %12, align 8, !tbaa !11
  %103 = load double, ptr %17, align 8, !tbaa !11
  %104 = load ptr, ptr %6, align 8, !tbaa !5
  %105 = getelementptr inbounds double, ptr %104, i64 2
  %106 = load double, ptr %105, align 8, !tbaa !11
  %107 = call double @llvm.fmuladd.f64(double %102, double %103, double %106)
  store double %107, ptr %105, align 8, !tbaa !11
  %108 = load double, ptr %13, align 8, !tbaa !11
  %109 = load double, ptr %15, align 8, !tbaa !11
  %110 = load ptr, ptr %6, align 8, !tbaa !5
  %111 = getelementptr inbounds double, ptr %110, i64 3
  %112 = load double, ptr %111, align 8, !tbaa !11
  %113 = call double @llvm.fmuladd.f64(double %108, double %109, double %112)
  store double %113, ptr %111, align 8, !tbaa !11
  %114 = load double, ptr %13, align 8, !tbaa !11
  %115 = load double, ptr %16, align 8, !tbaa !11
  %116 = load ptr, ptr %6, align 8, !tbaa !5
  %117 = getelementptr inbounds double, ptr %116, i64 4
  %118 = load double, ptr %117, align 8, !tbaa !11
  %119 = call double @llvm.fmuladd.f64(double %114, double %115, double %118)
  store double %119, ptr %117, align 8, !tbaa !11
  %120 = load double, ptr %13, align 8, !tbaa !11
  %121 = load double, ptr %17, align 8, !tbaa !11
  %122 = load ptr, ptr %6, align 8, !tbaa !5
  %123 = getelementptr inbounds double, ptr %122, i64 5
  %124 = load double, ptr %123, align 8, !tbaa !11
  %125 = call double @llvm.fmuladd.f64(double %120, double %121, double %124)
  store double %125, ptr %123, align 8, !tbaa !11
  %126 = load double, ptr %14, align 8, !tbaa !11
  %127 = load double, ptr %15, align 8, !tbaa !11
  %128 = load ptr, ptr %6, align 8, !tbaa !5
  %129 = getelementptr inbounds double, ptr %128, i64 6
  %130 = load double, ptr %129, align 8, !tbaa !11
  %131 = call double @llvm.fmuladd.f64(double %126, double %127, double %130)
  store double %131, ptr %129, align 8, !tbaa !11
  %132 = load double, ptr %14, align 8, !tbaa !11
  %133 = load double, ptr %16, align 8, !tbaa !11
  %134 = load ptr, ptr %6, align 8, !tbaa !5
  %135 = getelementptr inbounds double, ptr %134, i64 7
  %136 = load double, ptr %135, align 8, !tbaa !11
  %137 = call double @llvm.fmuladd.f64(double %132, double %133, double %136)
  store double %137, ptr %135, align 8, !tbaa !11
  %138 = load double, ptr %14, align 8, !tbaa !11
  %139 = load double, ptr %17, align 8, !tbaa !11
  %140 = load ptr, ptr %6, align 8, !tbaa !5
  %141 = getelementptr inbounds double, ptr %140, i64 8
  %142 = load double, ptr %141, align 8, !tbaa !11
  %143 = call double @llvm.fmuladd.f64(double %138, double %139, double %142)
  store double %143, ptr %141, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  br label %144

144:                                              ; preds = %41
  %145 = load i32, ptr %11, align 4, !tbaa !9
  %146 = add nsw i32 %145, 1
  store i32 %146, ptr %11, align 4, !tbaa !9
  br label %36, !llvm.loop !14

147:                                              ; preds = %40
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress 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 #3 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #0

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @_ZN3ptm12InnerProductEPdiPA3_KdPA3_dPa(ptr nocapture noundef writeonly %0, i32 noundef %1, ptr nocapture noundef readonly %2, ptr nocapture noundef readonly %3, ptr nocapture noundef readonly %4) local_unnamed_addr #1 {
  %6 = getelementptr inbounds i8, ptr %0, i64 64
  %7 = getelementptr inbounds i8, ptr %0, i64 48
  %8 = getelementptr inbounds i8, ptr %0, i64 32
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  %10 = icmp sgt i32 %1, 0
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(72) %0, i8 0, i64 72, i1 false)
  br i1 %10, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %5
  %wide.trip.count = zext nneg i32 %1 to i64
  br label %11

._crit_edge:                                      ; preds = %11, %5
  ret void

11:                                               ; preds = %.lr.ph, %11
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %11 ]
  %12 = phi double [ 0.000000e+00, %.lr.ph ], [ %39, %11 ]
  %13 = phi <2 x double> [ zeroinitializer, %.lr.ph ], [ %29, %11 ]
  %14 = phi <2 x double> [ zeroinitializer, %.lr.ph ], [ %32, %11 ]
  %15 = phi <2 x double> [ zeroinitializer, %.lr.ph ], [ %35, %11 ]
  %16 = phi <2 x double> [ zeroinitializer, %.lr.ph ], [ %38, %11 ]
  %17 = getelementptr inbounds [3 x double], ptr %2, i64 %indvars.iv
  %18 = getelementptr inbounds i8, ptr %17, i64 16
  %19 = load double, ptr %18, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %4, i64 %indvars.iv
  %21 = load i8, ptr %20, align 1, !tbaa !9
  %22 = sext i8 %21 to i64
  %23 = getelementptr inbounds [3 x double], ptr %3, i64 %22
  %24 = getelementptr inbounds i8, ptr %23, i64 16
  %25 = load double, ptr %24, align 8, !tbaa !5
  %26 = load <2 x double>, ptr %23, align 8, !tbaa !5
  %27 = load <2 x double>, ptr %17, align 8, !tbaa !5
  %28 = shufflevector <2 x double> %27, <2 x double> poison, <2 x i32> zeroinitializer
  %29 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %28, <2 x double> %26, <2 x double> %13)
  store <2 x double> %29, ptr %0, align 8, !tbaa !5
  %30 = shufflevector <2 x double> %26, <2 x double> poison, <2 x i32> <i32 1, i32 0>
  %31 = insertelement <2 x double> %30, double %25, i64 0
  %32 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %27, <2 x double> %31, <2 x double> %14)
  store <2 x double> %32, ptr %9, align 8, !tbaa !5
  %33 = shufflevector <2 x double> %27, <2 x double> poison, <2 x i32> <i32 1, i32 1>
  %34 = insertelement <2 x double> %30, double %25, i64 1
  %35 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %33, <2 x double> %34, <2 x double> %15)
  store <2 x double> %35, ptr %8, align 8, !tbaa !5
  %36 = insertelement <2 x double> poison, double %19, i64 0
  %37 = shufflevector <2 x double> %36, <2 x double> poison, <2 x i32> zeroinitializer
  %38 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %37, <2 x double> %26, <2 x double> %16)
  store <2 x double> %38, ptr %7, align 8, !tbaa !5
  %39 = tail call double @llvm.fmuladd.f64(double %19, double %25, double %12)
  store double %39, ptr %6, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %11, !llvm.loop !10
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { mustprogress nofree norecurse nosync nounwind memory(argmem: readwrite) 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,MemCpyOptPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass