; LLVM IR from Tiramisu-Compiler/tiramisu :: benchmarks/linear_algebra/cg/ddot.ll (Z10hpccg_ddotiPKdS0_Pd)

; 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: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z10hpccg_ddotiPKdS0_Pd(i32 noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca double, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  store double 0.000000e+00, ptr %9, align 8, !tbaa !11
  %12 = load ptr, ptr %7, align 8, !tbaa !9
  %13 = load ptr, ptr %6, align 8, !tbaa !9
  %14 = icmp eq ptr %12, %13
  br i1 %14, label %15, label %38

15:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %34, %15
  %17 = load i32, ptr %10, align 4, !tbaa !5
  %18 = load i32, ptr %5, align 4, !tbaa !5
  %19 = icmp slt i32 %17, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %37

21:                                               ; preds = %16
  %22 = load ptr, ptr %6, align 8, !tbaa !9
  %23 = load i32, ptr %10, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds double, ptr %22, i64 %24
  %26 = load double, ptr %25, align 8, !tbaa !11
  %27 = load ptr, ptr %6, align 8, !tbaa !9
  %28 = load i32, ptr %10, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds double, ptr %27, i64 %29
  %31 = load double, ptr %30, align 8, !tbaa !11
  %32 = load double, ptr %9, align 8, !tbaa !11
  %33 = call double @llvm.fmuladd.f64(double %26, double %31, double %32)
  store double %33, ptr %9, align 8, !tbaa !11
  br label %34

34:                                               ; preds = %21
  %35 = load i32, ptr %10, align 4, !tbaa !5
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr %10, align 4, !tbaa !5
  br label %16, !llvm.loop !13

37:                                               ; preds = %20
  br label %61

38:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %11, align 4, !tbaa !5
  br label %39

39:                                               ; preds = %57, %38
  %40 = load i32, ptr %11, align 4, !tbaa !5
  %41 = load i32, ptr %5, align 4, !tbaa !5
  %42 = icmp slt i32 %40, %41
  br i1 %42, label %44, label %43

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

44:                                               ; preds = %39
  %45 = load ptr, ptr %6, align 8, !tbaa !9
  %46 = load i32, ptr %11, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds double, ptr %45, i64 %47
  %49 = load double, ptr %48, align 8, !tbaa !11
  %50 = load ptr, ptr %7, align 8, !tbaa !9
  %51 = load i32, ptr %11, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds double, ptr %50, i64 %52
  %54 = load double, ptr %53, align 8, !tbaa !11
  %55 = load double, ptr %9, align 8, !tbaa !11
  %56 = call double @llvm.fmuladd.f64(double %49, double %54, double %55)
  store double %56, ptr %9, align 8, !tbaa !11
  br label %57

57:                                               ; preds = %44
  %58 = load i32, ptr %11, align 4, !tbaa !5
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %11, align 4, !tbaa !5
  br label %39, !llvm.loop !15

60:                                               ; preds = %43
  br label %61

61:                                               ; preds = %60, %37
  %62 = load double, ptr %9, align 8, !tbaa !11
  %63 = load ptr, ptr %8, align 8, !tbaa !9
  store double %62, ptr %63, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  ret i32 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 speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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


; 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 nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local noundef i32 @_Z10hpccg_ddotiPKdS0_Pd(i32 noundef %0, ptr noundef readonly %1, ptr noundef readonly %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #0 {
  %5 = icmp eq ptr %2, %1
  %6 = icmp sgt i32 %0, 0
  br i1 %5, label %.preheader, label %.preheader24

.preheader24:                                     ; preds = %4
  br i1 %6, label %.lr.ph.preheader, label %.loopexit

.lr.ph.preheader:                                 ; preds = %.preheader24
  %wide.trip.count = zext nneg i32 %0 to i64
  %xtraiter = and i64 %wide.trip.count, 3
  %7 = icmp ult i32 %0, 4
  br i1 %7, label %.loopexit.loopexit44.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %wide.trip.count, 2147483644
  br label %.lr.ph

.preheader:                                       ; preds = %4
  br i1 %6, label %.lr.ph30.preheader, label %.loopexit

.lr.ph30.preheader:                               ; preds = %.preheader
  %wide.trip.count38 = zext nneg i32 %0 to i64
  %xtraiter47 = and i64 %wide.trip.count38, 3
  %8 = icmp ult i32 %0, 4
  br i1 %8, label %.loopexit.loopexit.unr-lcssa, label %.lr.ph30.preheader.new

.lr.ph30.preheader.new:                           ; preds = %.lr.ph30.preheader
  %unroll_iter51 = and i64 %wide.trip.count38, 2147483644
  br label %.lr.ph30

.lr.ph30:                                         ; preds = %.lr.ph30, %.lr.ph30.preheader.new
  %indvars.iv35 = phi i64 [ 0, %.lr.ph30.preheader.new ], [ %indvars.iv.next36.3, %.lr.ph30 ]
  %.02028 = phi double [ 0.000000e+00, %.lr.ph30.preheader.new ], [ %20, %.lr.ph30 ]
  %niter52 = phi i64 [ 0, %.lr.ph30.preheader.new ], [ %niter52.next.3, %.lr.ph30 ]
  %9 = getelementptr inbounds double, ptr %1, i64 %indvars.iv35
  %10 = load double, ptr %9, align 8, !tbaa !5
  %11 = tail call double @llvm.fmuladd.f64(double %10, double %10, double %.02028)
  %indvars.iv.next36 = or disjoint i64 %indvars.iv35, 1
  %12 = getelementptr inbounds double, ptr %1, i64 %indvars.iv.next36
  %13 = load double, ptr %12, align 8, !tbaa !5
  %14 = tail call double @llvm.fmuladd.f64(double %13, double %13, double %11)
  %indvars.iv.next36.1 = or disjoint i64 %indvars.iv35, 2
  %15 = getelementptr inbounds double, ptr %1, i64 %indvars.iv.next36.1
  %16 = load double, ptr %15, align 8, !tbaa !5
  %17 = tail call double @llvm.fmuladd.f64(double %16, double %16, double %14)
  %indvars.iv.next36.2 = or disjoint i64 %indvars.iv35, 3
  %18 = getelementptr inbounds double, ptr %1, i64 %indvars.iv.next36.2
  %19 = load double, ptr %18, align 8, !tbaa !5
  %20 = tail call double @llvm.fmuladd.f64(double %19, double %19, double %17)
  %indvars.iv.next36.3 = add nuw nsw i64 %indvars.iv35, 4
  %niter52.next.3 = add i64 %niter52, 4
  %niter52.ncmp.3 = icmp eq i64 %niter52.next.3, %unroll_iter51
  br i1 %niter52.ncmp.3, label %.loopexit.loopexit.unr-lcssa, label %.lr.ph30, !llvm.loop !9

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader.new ], [ %indvars.iv.next.3, %.lr.ph ]
  %.126 = phi double [ 0.000000e+00, %.lr.ph.preheader.new ], [ %40, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.3, %.lr.ph ]
  %21 = getelementptr inbounds double, ptr %1, i64 %indvars.iv
  %22 = load double, ptr %21, align 8, !tbaa !5
  %23 = getelementptr inbounds double, ptr %2, i64 %indvars.iv
  %24 = load double, ptr %23, align 8, !tbaa !5
  %25 = tail call double @llvm.fmuladd.f64(double %22, double %24, double %.126)
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %26 = getelementptr inbounds double, ptr %1, i64 %indvars.iv.next
  %27 = load double, ptr %26, align 8, !tbaa !5
  %28 = getelementptr inbounds double, ptr %2, i64 %indvars.iv.next
  %29 = load double, ptr %28, align 8, !tbaa !5
  %30 = tail call double @llvm.fmuladd.f64(double %27, double %29, double %25)
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %31 = getelementptr inbounds double, ptr %1, i64 %indvars.iv.next.1
  %32 = load double, ptr %31, align 8, !tbaa !5
  %33 = getelementptr inbounds double, ptr %2, i64 %indvars.iv.next.1
  %34 = load double, ptr %33, align 8, !tbaa !5
  %35 = tail call double @llvm.fmuladd.f64(double %32, double %34, double %30)
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %36 = getelementptr inbounds double, ptr %1, i64 %indvars.iv.next.2
  %37 = load double, ptr %36, align 8, !tbaa !5
  %38 = getelementptr inbounds double, ptr %2, i64 %indvars.iv.next.2
  %39 = load double, ptr %38, align 8, !tbaa !5
  %40 = tail call double @llvm.fmuladd.f64(double %37, double %39, double %35)
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %.loopexit.loopexit44.unr-lcssa, label %.lr.ph, !llvm.loop !11

.loopexit.loopexit.unr-lcssa:                     ; preds = %.lr.ph30, %.lr.ph30.preheader
  %.lcssa.ph = phi double [ poison, %.lr.ph30.preheader ], [ %20, %.lr.ph30 ]
  %indvars.iv35.unr = phi i64 [ 0, %.lr.ph30.preheader ], [ %indvars.iv.next36.3, %.lr.ph30 ]
  %.02028.unr = phi double [ 0.000000e+00, %.lr.ph30.preheader ], [ %20, %.lr.ph30 ]
  %lcmp.mod49.not = icmp eq i64 %xtraiter47, 0
  br i1 %lcmp.mod49.not, label %.loopexit, label %.lr.ph30.epil

.lr.ph30.epil:                                    ; preds = %.loopexit.loopexit.unr-lcssa, %.lr.ph30.epil
  %indvars.iv35.epil = phi i64 [ %indvars.iv.next36.epil, %.lr.ph30.epil ], [ %indvars.iv35.unr, %.loopexit.loopexit.unr-lcssa ]
  %.02028.epil = phi double [ %43, %.lr.ph30.epil ], [ %.02028.unr, %.loopexit.loopexit.unr-lcssa ]
  %epil.iter48 = phi i64 [ %epil.iter48.next, %.lr.ph30.epil ], [ 0, %.loopexit.loopexit.unr-lcssa ]
  %41 = getelementptr inbounds double, ptr %1, i64 %indvars.iv35.epil
  %42 = load double, ptr %41, align 8, !tbaa !5
  %43 = tail call double @llvm.fmuladd.f64(double %42, double %42, double %.02028.epil)
  %indvars.iv.next36.epil = add nuw nsw i64 %indvars.iv35.epil, 1
  %epil.iter48.next = add i64 %epil.iter48, 1
  %epil.iter48.cmp.not = icmp eq i64 %epil.iter48.next, %xtraiter47
  br i1 %epil.iter48.cmp.not, label %.loopexit, label %.lr.ph30.epil, !llvm.loop !12

.loopexit.loopexit44.unr-lcssa:                   ; preds = %.lr.ph, %.lr.ph.preheader
  %.lcssa45.ph = phi double [ poison, %.lr.ph.preheader ], [ %40, %.lr.ph ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next.3, %.lr.ph ]
  %.126.unr = phi double [ 0.000000e+00, %.lr.ph.preheader ], [ %40, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.loopexit, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %.loopexit.loopexit44.unr-lcssa, %.lr.ph.epil
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.lr.ph.epil ], [ %indvars.iv.unr, %.loopexit.loopexit44.unr-lcssa ]
  %.126.epil = phi double [ %48, %.lr.ph.epil ], [ %.126.unr, %.loopexit.loopexit44.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %.loopexit.loopexit44.unr-lcssa ]
  %44 = getelementptr inbounds double, ptr %1, i64 %indvars.iv.epil
  %45 = load double, ptr %44, align 8, !tbaa !5
  %46 = getelementptr inbounds double, ptr %2, i64 %indvars.iv.epil
  %47 = load double, ptr %46, align 8, !tbaa !5
  %48 = tail call double @llvm.fmuladd.f64(double %45, double %47, double %.126.epil)
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %.loopexit, label %.lr.ph.epil, !llvm.loop !14

.loopexit:                                        ; preds = %.loopexit.loopexit44.unr-lcssa, %.lr.ph.epil, %.loopexit.loopexit.unr-lcssa, %.lr.ph30.epil, %.preheader24, %.preheader
  %.2 = phi double [ 0.000000e+00, %.preheader ], [ 0.000000e+00, %.preheader24 ], [ %.lcssa.ph, %.loopexit.loopexit.unr-lcssa ], [ %43, %.lr.ph30.epil ], [ %.lcssa45.ph, %.loopexit.loopexit44.unr-lcssa ], [ %48, %.lr.ph.epil ]
  store double %.2, ptr %3, align 8, !tbaa !5
  ret i32 0
}

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

attributes #0 = { 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 #1 = { mustprogress 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.unroll.disable"}
!14 = distinct !{!14, !13}


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