; LLVM IR from microsoft/LightAIMD :: src/einsum.ll_einsum_mn_mn (m)

; 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 willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; 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 @einsum_mn_mn__m(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3, i64 noundef %4) #2 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i32, align 4
  %13 = alloca double, align 8
  %14 = alloca i64, align 8
  %15 = alloca i64, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i64 %3, ptr %9, align 8, !tbaa !9
  store i64 %4, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  store i64 0, ptr %11, align 8, !tbaa !9
  br label %16

16:                                               ; preds = %53, %5
  %17 = load i64, ptr %11, align 8, !tbaa !9
  %18 = load i64, ptr %9, align 8, !tbaa !9
  %19 = icmp ult i64 %17, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %16
  store i32 2, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  br label %56

21:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  store double 0.000000e+00, ptr %13, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %22 = load i64, ptr %11, align 8, !tbaa !9
  %23 = load i64, ptr %10, align 8, !tbaa !9
  %24 = mul i64 %22, %23
  store i64 %24, ptr %14, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  store i64 0, ptr %15, align 8, !tbaa !9
  br label %25

25:                                               ; preds = %45, %21
  %26 = load i64, ptr %15, align 8, !tbaa !9
  %27 = load i64, ptr %10, align 8, !tbaa !9
  %28 = icmp ult i64 %26, %27
  br i1 %28, label %30, label %29

29:                                               ; preds = %25
  store i32 5, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  br label %48

30:                                               ; preds = %25
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = load i64, ptr %14, align 8, !tbaa !9
  %33 = load i64, ptr %15, align 8, !tbaa !9
  %34 = add i64 %32, %33
  %35 = getelementptr inbounds double, ptr %31, i64 %34
  %36 = load double, ptr %35, align 8, !tbaa !11
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = load i64, ptr %14, align 8, !tbaa !9
  %39 = load i64, ptr %15, align 8, !tbaa !9
  %40 = add i64 %38, %39
  %41 = getelementptr inbounds double, ptr %37, i64 %40
  %42 = load double, ptr %41, align 8, !tbaa !11
  %43 = load double, ptr %13, align 8, !tbaa !11
  %44 = call double @llvm.fmuladd.f64(double %36, double %42, double %43)
  store double %44, ptr %13, align 8, !tbaa !11
  br label %45

45:                                               ; preds = %30
  %46 = load i64, ptr %15, align 8, !tbaa !9
  %47 = add i64 %46, 1
  store i64 %47, ptr %15, align 8, !tbaa !9
  br label %25, !llvm.loop !13

48:                                               ; preds = %29
  %49 = load double, ptr %13, align 8, !tbaa !11
  %50 = load ptr, ptr %8, align 8, !tbaa !5
  %51 = load i64, ptr %11, align 8, !tbaa !9
  %52 = getelementptr inbounds double, ptr %50, i64 %51
  store double %49, ptr %52, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  br label %53

53:                                               ; preds = %48
  %54 = load i64, ptr %11, align 8, !tbaa !9
  %55 = add i64 %54, 1
  store i64 %55, ptr %11, align 8, !tbaa !9
  br label %16, !llvm.loop !15

56:                                               ; preds = %20
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !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 nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #0

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @einsum_mn_mn__m(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr nocapture noundef writeonly %2, i64 noundef %3, i64 noundef %4) local_unnamed_addr #1 {
  %.not = icmp eq i64 %3, 0
  br i1 %.not, label %._crit_edge24, label %.lr.ph23

.lr.ph23:                                         ; preds = %5
  %.not25 = icmp eq i64 %4, 0
  br i1 %.not25, label %.lr.ph23.split.preheader, label %.lr.ph.us.preheader

.lr.ph.us.preheader:                              ; preds = %.lr.ph23
  %xtraiter = and i64 %4, 3
  %6 = icmp ult i64 %4, 4
  %unroll_iter = and i64 %4, -4
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.lr.ph.us

.lr.ph23.split.preheader:                         ; preds = %.lr.ph23
  %7 = shl nuw i64 %3, 3
  tail call void @llvm.memset.p0.i64(ptr align 8 %2, i8 0, i64 %7, i1 false), !tbaa !5
  br label %._crit_edge24

.lr.ph.us:                                        ; preds = %.lr.ph.us.preheader, %._crit_edge.us
  %.01721.us = phi i64 [ %45, %._crit_edge.us ], [ 0, %.lr.ph.us.preheader ]
  %8 = mul i64 %.01721.us, %4
  br i1 %6, label %._crit_edge.us.unr-lcssa, label %.lr.ph.us.new

.lr.ph.us.new:                                    ; preds = %.lr.ph.us, %.lr.ph.us.new
  %.020.us = phi i64 [ %36, %.lr.ph.us.new ], [ 0, %.lr.ph.us ]
  %.01819.us = phi double [ %35, %.lr.ph.us.new ], [ 0.000000e+00, %.lr.ph.us ]
  %niter = phi i64 [ %niter.next.3, %.lr.ph.us.new ], [ 0, %.lr.ph.us ]
  %9 = add i64 %.020.us, %8
  %10 = getelementptr inbounds double, ptr %0, i64 %9
  %11 = load double, ptr %10, align 8, !tbaa !5
  %12 = getelementptr inbounds double, ptr %1, i64 %9
  %13 = load double, ptr %12, align 8, !tbaa !5
  %14 = tail call double @llvm.fmuladd.f64(double %11, double %13, double %.01819.us)
  %15 = or disjoint i64 %.020.us, 1
  %16 = add i64 %15, %8
  %17 = getelementptr inbounds double, ptr %0, i64 %16
  %18 = load double, ptr %17, align 8, !tbaa !5
  %19 = getelementptr inbounds double, ptr %1, i64 %16
  %20 = load double, ptr %19, align 8, !tbaa !5
  %21 = tail call double @llvm.fmuladd.f64(double %18, double %20, double %14)
  %22 = or disjoint i64 %.020.us, 2
  %23 = add i64 %22, %8
  %24 = getelementptr inbounds double, ptr %0, i64 %23
  %25 = load double, ptr %24, align 8, !tbaa !5
  %26 = getelementptr inbounds double, ptr %1, i64 %23
  %27 = load double, ptr %26, align 8, !tbaa !5
  %28 = tail call double @llvm.fmuladd.f64(double %25, double %27, double %21)
  %29 = or disjoint i64 %.020.us, 3
  %30 = add i64 %29, %8
  %31 = getelementptr inbounds double, ptr %0, i64 %30
  %32 = load double, ptr %31, align 8, !tbaa !5
  %33 = getelementptr inbounds double, ptr %1, i64 %30
  %34 = load double, ptr %33, align 8, !tbaa !5
  %35 = tail call double @llvm.fmuladd.f64(double %32, double %34, double %28)
  %36 = add nuw i64 %.020.us, 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 %._crit_edge.us.unr-lcssa, label %.lr.ph.us.new, !llvm.loop !9

._crit_edge.us.unr-lcssa:                         ; preds = %.lr.ph.us.new, %.lr.ph.us
  %.lcssa.ph = phi double [ poison, %.lr.ph.us ], [ %35, %.lr.ph.us.new ]
  %.020.us.unr = phi i64 [ 0, %.lr.ph.us ], [ %36, %.lr.ph.us.new ]
  %.01819.us.unr = phi double [ 0.000000e+00, %.lr.ph.us ], [ %35, %.lr.ph.us.new ]
  br i1 %lcmp.mod.not, label %._crit_edge.us, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.us.unr-lcssa, %.epil.preheader
  %.020.us.epil = phi i64 [ %43, %.epil.preheader ], [ %.020.us.unr, %._crit_edge.us.unr-lcssa ]
  %.01819.us.epil = phi double [ %42, %.epil.preheader ], [ %.01819.us.unr, %._crit_edge.us.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %._crit_edge.us.unr-lcssa ]
  %37 = add i64 %.020.us.epil, %8
  %38 = getelementptr inbounds double, ptr %0, i64 %37
  %39 = load double, ptr %38, align 8, !tbaa !5
  %40 = getelementptr inbounds double, ptr %1, i64 %37
  %41 = load double, ptr %40, align 8, !tbaa !5
  %42 = tail call double @llvm.fmuladd.f64(double %39, double %41, double %.01819.us.epil)
  %43 = add nuw i64 %.020.us.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 %._crit_edge.us, label %.epil.preheader, !llvm.loop !11

._crit_edge.us:                                   ; preds = %.epil.preheader, %._crit_edge.us.unr-lcssa
  %.lcssa = phi double [ %.lcssa.ph, %._crit_edge.us.unr-lcssa ], [ %42, %.epil.preheader ]
  %44 = getelementptr inbounds double, ptr %2, i64 %.01721.us
  store double %.lcssa, ptr %44, align 8, !tbaa !5
  %45 = add nuw i64 %.01721.us, 1
  %exitcond27.not = icmp eq i64 %45, %3
  br i1 %exitcond27.not, label %._crit_edge24, label %.lr.ph.us, !llvm.loop !13

._crit_edge24:                                    ; preds = %._crit_edge.us, %.lr.ph23.split.preheader, %5
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { 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) }

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


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