; LLVM IR from VT-ICAM/cfem :: cfem (cf_diagonal_multiply)

; 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: nounwind uwtable
define dso_local void @cf_diagonal_multiply(i32 noundef %0, i32 noundef %1, ptr noundef nonnull align 8 %2, ptr noundef nonnull align 8 %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !9
  %11 = load i32, ptr %5, align 4, !tbaa !5
  %12 = load i32, ptr %6, align 4, !tbaa !5
  %13 = mul nsw i32 %11, %12
  %14 = zext i32 %13 to i64
  %15 = load i32, ptr %6, align 4, !tbaa !5
  %16 = zext i32 %15 to i64
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  store i32 0, ptr %9, align 4, !tbaa !5
  br label %17

17:                                               ; preds = %46, %4
  %18 = load i32, ptr %9, align 4, !tbaa !5
  %19 = load i32, ptr %5, align 4, !tbaa !5
  %20 = icmp slt i32 %18, %19
  br i1 %20, label %21, label %49

21:                                               ; preds = %17
  store i32 0, ptr %10, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %42, %21
  %23 = load i32, ptr %10, align 4, !tbaa !5
  %24 = load i32, ptr %6, align 4, !tbaa !5
  %25 = icmp slt i32 %23, %24
  br i1 %25, label %26, label %45

26:                                               ; preds = %22
  %27 = load ptr, ptr %8, 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 ptr, ptr %7, align 8, !tbaa !9
  %33 = load i32, ptr %9, align 4, !tbaa !5
  %34 = load i32, ptr %6, align 4, !tbaa !5
  %35 = mul nsw i32 %33, %34
  %36 = load i32, ptr %10, align 4, !tbaa !5
  %37 = add nsw i32 %35, %36
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds double, ptr %32, i64 %38
  %40 = load double, ptr %39, align 8, !tbaa !11
  %41 = fmul double %40, %31
  store double %41, ptr %39, align 8, !tbaa !11
  br label %42

42:                                               ; preds = %26
  %43 = load i32, ptr %10, align 4, !tbaa !5
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %10, align 4, !tbaa !5
  br label %22, !llvm.loop !13

45:                                               ; preds = %22
  br label %46

46:                                               ; preds = %45
  %47 = load i32, ptr %9, align 4, !tbaa !5
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %9, align 4, !tbaa !5
  br label %17, !llvm.loop !15

49:                                               ; preds = %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #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 = !{!"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: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @cf_diagonal_multiply(i32 noundef %0, i32 noundef %1, ptr nocapture noundef nonnull align 8 %2, ptr nocapture noundef nonnull readonly align 8 %3) local_unnamed_addr #0 {
  %5 = icmp sgt i32 %0, 0
  %6 = icmp sgt i32 %1, 0
  %or.cond = and i1 %5, %6
  br i1 %or.cond, label %.preheader.us.preheader, label %._crit_edge18

.preheader.us.preheader:                          ; preds = %4
  %7 = zext nneg i32 %1 to i64
  %wide.trip.count24 = zext nneg i32 %0 to i64
  %8 = mul nuw nsw i64 %7, %wide.trip.count24
  %9 = shl i64 %8, 3
  %scevgep = getelementptr i8, ptr %2, i64 %9
  %10 = shl nuw nsw i64 %7, 3
  %scevgep26 = getelementptr i8, ptr %3, i64 %10
  %min.iters.check = icmp ult i32 %1, 4
  %bound0 = icmp ugt ptr %scevgep26, %2
  %bound1 = icmp ugt ptr %scevgep, %3
  %found.conflict = and i1 %bound0, %bound1
  %n.vec = and i64 %7, 2147483644
  %cmp.n = icmp eq i64 %n.vec, %7
  %xtraiter = and i64 %7, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %indvars.iv21 = phi i64 [ 0, %.preheader.us.preheader ], [ %indvars.iv.next22, %._crit_edge.us ]
  %11 = mul nuw nsw i64 %indvars.iv21, %7
  %invariant.gep = getelementptr inbounds double, ptr %2, i64 %11
  %brmerge = select i1 %min.iters.check, i1 true, i1 %found.conflict
  br i1 %brmerge, label %scalar.ph.preheader, label %vector.body

vector.body:                                      ; preds = %.preheader.us, %vector.body
  %index = phi i64 [ %index.next, %vector.body ], [ 0, %.preheader.us ]
  %12 = getelementptr inbounds double, ptr %3, i64 %index
  %13 = getelementptr inbounds i8, ptr %12, i64 16
  %wide.load = load <2 x double>, ptr %12, align 8, !tbaa !5, !alias.scope !9
  %wide.load27 = load <2 x double>, ptr %13, align 8, !tbaa !5, !alias.scope !9
  %14 = getelementptr inbounds double, ptr %invariant.gep, i64 %index
  %15 = getelementptr inbounds i8, ptr %14, i64 16
  %wide.load28 = load <2 x double>, ptr %14, align 8, !tbaa !5, !alias.scope !12, !noalias !9
  %wide.load29 = load <2 x double>, ptr %15, align 8, !tbaa !5, !alias.scope !12, !noalias !9
  %16 = fmul <2 x double> %wide.load, %wide.load28
  %17 = fmul <2 x double> %wide.load27, %wide.load29
  store <2 x double> %16, ptr %14, align 8, !tbaa !5, !alias.scope !12, !noalias !9
  store <2 x double> %17, ptr %15, align 8, !tbaa !5, !alias.scope !12, !noalias !9
  %index.next = add nuw i64 %index, 4
  %18 = icmp eq i64 %index.next, %n.vec
  br i1 %18, label %middle.block, label %vector.body, !llvm.loop !14

middle.block:                                     ; preds = %vector.body
  br i1 %cmp.n, label %._crit_edge.us, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %.preheader.us, %middle.block
  %indvars.iv.ph = phi i64 [ 0, %.preheader.us ], [ %n.vec, %middle.block ]
  br i1 %lcmp.mod.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol

scalar.ph.prol:                                   ; preds = %scalar.ph.preheader, %scalar.ph.prol
  %indvars.iv.prol = phi i64 [ %indvars.iv.next.prol, %scalar.ph.prol ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %scalar.ph.prol ], [ 0, %scalar.ph.preheader ]
  %19 = getelementptr inbounds double, ptr %3, i64 %indvars.iv.prol
  %20 = load double, ptr %19, align 8, !tbaa !5
  %gep.prol = getelementptr inbounds double, ptr %invariant.gep, i64 %indvars.iv.prol
  %21 = load double, ptr %gep.prol, align 8, !tbaa !5
  %22 = fmul double %20, %21
  store double %22, ptr %gep.prol, align 8, !tbaa !5
  %indvars.iv.next.prol = add nuw nsw i64 %indvars.iv.prol, 1
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol, !llvm.loop !18

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol, %scalar.ph.preheader
  %indvars.iv.unr = phi i64 [ %indvars.iv.ph, %scalar.ph.preheader ], [ %indvars.iv.next.prol, %scalar.ph.prol ]
  %23 = sub nsw i64 %indvars.iv.ph, %7
  %24 = icmp ugt i64 %23, -4
  br i1 %24, label %._crit_edge.us, label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next.3, %scalar.ph ], [ %indvars.iv.unr, %scalar.ph.prol.loopexit ]
  %25 = getelementptr inbounds double, ptr %3, i64 %indvars.iv
  %26 = load double, ptr %25, align 8, !tbaa !5
  %gep = getelementptr inbounds double, ptr %invariant.gep, i64 %indvars.iv
  %27 = load double, ptr %gep, align 8, !tbaa !5
  %28 = fmul double %26, %27
  store double %28, ptr %gep, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %29 = getelementptr inbounds double, ptr %3, i64 %indvars.iv.next
  %30 = load double, ptr %29, align 8, !tbaa !5
  %gep.1 = getelementptr inbounds double, ptr %invariant.gep, i64 %indvars.iv.next
  %31 = load double, ptr %gep.1, align 8, !tbaa !5
  %32 = fmul double %30, %31
  store double %32, ptr %gep.1, align 8, !tbaa !5
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %33 = getelementptr inbounds double, ptr %3, i64 %indvars.iv.next.1
  %34 = load double, ptr %33, align 8, !tbaa !5
  %gep.2 = getelementptr inbounds double, ptr %invariant.gep, i64 %indvars.iv.next.1
  %35 = load double, ptr %gep.2, align 8, !tbaa !5
  %36 = fmul double %34, %35
  store double %36, ptr %gep.2, align 8, !tbaa !5
  %indvars.iv.next.2 = add nuw nsw i64 %indvars.iv, 3
  %37 = getelementptr inbounds double, ptr %3, i64 %indvars.iv.next.2
  %38 = load double, ptr %37, align 8, !tbaa !5
  %gep.3 = getelementptr inbounds double, ptr %invariant.gep, i64 %indvars.iv.next.2
  %39 = load double, ptr %gep.3, align 8, !tbaa !5
  %40 = fmul double %38, %39
  store double %40, ptr %gep.3, align 8, !tbaa !5
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %exitcond.not.3 = icmp eq i64 %indvars.iv.next.3, %7
  br i1 %exitcond.not.3, label %._crit_edge.us, label %scalar.ph, !llvm.loop !20

._crit_edge.us:                                   ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block
  %indvars.iv.next22 = add nuw nsw i64 %indvars.iv21, 1
  %exitcond25.not = icmp eq i64 %indvars.iv.next22, %wide.trip.count24
  br i1 %exitcond25.not, label %._crit_edge18, label %.preheader.us, !llvm.loop !21

._crit_edge18:                                    ; preds = %._crit_edge.us, %4
  ret void
}

attributes #0 = { 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" }

!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 = !{!10}
!10 = distinct !{!10, !11}
!11 = distinct !{!11, !"LVerDomain"}
!12 = !{!13}
!13 = distinct !{!13, !11}
!14 = distinct !{!14, !15, !16, !17}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!"llvm.loop.isvectorized", i32 1}
!17 = !{!"llvm.loop.unroll.runtime.disable"}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.unroll.disable"}
!20 = distinct !{!20, !15, !16}
!21 = distinct !{!21, !15}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass