; LLVM IR from microsoft/LightAIMD :: src/einsum.ll_einsum_mn_np (mp)

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

19:                                               ; preds = %72, %6
  %20 = load i64, ptr %13, align 8, !tbaa !9
  %21 = load i64, ptr %10, align 8, !tbaa !9
  %22 = icmp ult i64 %20, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %19
  store i32 2, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  br label %75

24:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  %25 = load i64, ptr %13, align 8, !tbaa !9
  %26 = load i64, ptr %11, align 8, !tbaa !9
  %27 = mul i64 %25, %26
  store i64 %27, ptr %15, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  store i64 0, ptr %16, align 8, !tbaa !9
  br label %28

28:                                               ; preds = %68, %24
  %29 = load i64, ptr %16, align 8, !tbaa !9
  %30 = load i64, ptr %12, align 8, !tbaa !9
  %31 = icmp ult i64 %29, %30
  br i1 %31, label %33, label %32

32:                                               ; preds = %28
  store i32 5, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  br label %71

33:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #3
  store double 0.000000e+00, ptr %17, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #3
  store i64 0, ptr %18, align 8, !tbaa !9
  br label %34

34:                                               ; preds = %56, %33
  %35 = load i64, ptr %18, align 8, !tbaa !9
  %36 = load i64, ptr %11, align 8, !tbaa !9
  %37 = icmp ult i64 %35, %36
  br i1 %37, label %39, label %38

38:                                               ; preds = %34
  store i32 8, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #3
  br label %59

39:                                               ; preds = %34
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = load i64, ptr %15, align 8, !tbaa !9
  %42 = load i64, ptr %18, align 8, !tbaa !9
  %43 = add i64 %41, %42
  %44 = getelementptr inbounds double, ptr %40, i64 %43
  %45 = load double, ptr %44, align 8, !tbaa !11
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = load i64, ptr %18, align 8, !tbaa !9
  %48 = load i64, ptr %12, align 8, !tbaa !9
  %49 = mul i64 %47, %48
  %50 = load i64, ptr %16, align 8, !tbaa !9
  %51 = add i64 %49, %50
  %52 = getelementptr inbounds double, ptr %46, i64 %51
  %53 = load double, ptr %52, align 8, !tbaa !11
  %54 = load double, ptr %17, align 8, !tbaa !11
  %55 = call double @llvm.fmuladd.f64(double %45, double %53, double %54)
  store double %55, ptr %17, align 8, !tbaa !11
  br label %56

56:                                               ; preds = %39
  %57 = load i64, ptr %18, align 8, !tbaa !9
  %58 = add i64 %57, 1
  store i64 %58, ptr %18, align 8, !tbaa !9
  br label %34, !llvm.loop !13

59:                                               ; preds = %38
  %60 = load double, ptr %17, align 8, !tbaa !11
  %61 = load ptr, ptr %9, align 8, !tbaa !5
  %62 = load i64, ptr %13, align 8, !tbaa !9
  %63 = load i64, ptr %12, align 8, !tbaa !9
  %64 = mul i64 %62, %63
  %65 = load i64, ptr %16, align 8, !tbaa !9
  %66 = add i64 %64, %65
  %67 = getelementptr inbounds double, ptr %61, i64 %66
  store double %60, ptr %67, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #3
  br label %68

68:                                               ; preds = %59
  %69 = load i64, ptr %16, align 8, !tbaa !9
  %70 = add i64 %69, 1
  store i64 %70, ptr %16, align 8, !tbaa !9
  br label %28, !llvm.loop !15

71:                                               ; preds = %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  br label %72

72:                                               ; preds = %71
  %73 = load i64, ptr %13, align 8, !tbaa !9
  %74 = add i64 %73, 1
  store i64 %74, ptr %13, align 8, !tbaa !9
  br label %19, !llvm.loop !16

75:                                               ; preds = %23
  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 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 = { 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 = !{!"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}
!16 = distinct !{!16, !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 @einsum_mn_np__mp(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr nocapture noundef writeonly %2, i64 noundef %3, i64 noundef %4, i64 noundef %5) local_unnamed_addr #0 {
  %.not = icmp eq i64 %3, 0
  %.not36 = icmp eq i64 %5, 0
  %or.cond = or i1 %.not, %.not36
  br i1 %or.cond, label %._crit_edge, label %.lr.ph.split.us

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

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

.preheader.lr.ph.us.preheader:                    ; preds = %.lr.ph.split.us
  %8 = mul i64 %5, %3
  %9 = shl i64 %8, 3
  tail call void @llvm.memset.p0.i64(ptr align 8 %2, i8 0, i64 %9, i1 false), !tbaa !5
  br label %._crit_edge

.preheader.lr.ph.us.us:                           ; preds = %.preheader.lr.ph.us.us.preheader, %._crit_edge30.split.us.us.us
  %.02531.us.us = phi i64 [ %46, %._crit_edge30.split.us.us.us ], [ 0, %.preheader.lr.ph.us.us.preheader ]
  %10 = mul i64 %.02531.us.us, %4
  %11 = getelementptr double, ptr %0, i64 %10
  %12 = mul i64 %.02531.us.us, %5
  %13 = getelementptr double, ptr %2, i64 %12
  br label %.preheader.us.us.us

.preheader.us.us.us:                              ; preds = %._crit_edge.us.us.us, %.preheader.lr.ph.us.us
  %.02429.us.us.us = phi i64 [ 0, %.preheader.lr.ph.us.us ], [ %45, %._crit_edge.us.us.us ]
  %invariant.gep.us.us.us = getelementptr double, ptr %1, i64 %.02429.us.us.us
  br i1 %7, label %._crit_edge.us.us.us.unr-lcssa, label %.preheader.us.us.us.new

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

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

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

._crit_edge.us.us.us:                             ; preds = %.epil.preheader, %._crit_edge.us.us.us.unr-lcssa
  %.lcssa = phi double [ %.lcssa.ph, %._crit_edge.us.us.us.unr-lcssa ], [ %42, %.epil.preheader ]
  %44 = getelementptr double, ptr %13, i64 %.02429.us.us.us
  store double %.lcssa, ptr %44, align 8, !tbaa !5
  %45 = add nuw i64 %.02429.us.us.us, 1
  %exitcond40.not = icmp eq i64 %45, %5
  br i1 %exitcond40.not, label %._crit_edge30.split.us.us.us, label %.preheader.us.us.us, !llvm.loop !13

._crit_edge30.split.us.us.us:                     ; preds = %._crit_edge.us.us.us
  %46 = add nuw i64 %.02531.us.us, 1
  %exitcond41.not = icmp eq i64 %46, %3
  br i1 %exitcond41.not, label %._crit_edge, label %.preheader.lr.ph.us.us, !llvm.loop !14

._crit_edge:                                      ; preds = %._crit_edge30.split.us.us.us, %.preheader.lr.ph.us.preheader, %6
  ret void
}

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

; 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 = { 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) }
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}
!14 = distinct !{!14, !10}


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