; LLVM IR from microsoft/LightAIMD :: src/einsum.ll_einsumaa_mn_mp_m (np)

; 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 @einsumaa_mn_mp_m__np(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, i64 noundef %4, i64 noundef %5, i64 noundef %6) #2 {
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca i64, align 8
  %15 = alloca i64, align 8
  %16 = alloca i32, align 4
  %17 = alloca i64, align 8
  %18 = alloca double, align 8
  %19 = alloca i64, align 8
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store ptr %2, ptr %10, align 8, !tbaa !5
  store ptr %3, ptr %11, align 8, !tbaa !5
  store i64 %4, ptr %12, align 8, !tbaa !9
  store i64 %5, ptr %13, align 8, !tbaa !9
  store i64 %6, 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 %20

20:                                               ; preds = %79, %7
  %21 = load i64, ptr %15, align 8, !tbaa !9
  %22 = load i64, ptr %13, align 8, !tbaa !9
  %23 = icmp ult i64 %21, %22
  br i1 %23, label %25, label %24

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

25:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #3
  store i64 0, ptr %17, align 8, !tbaa !9
  br label %26

26:                                               ; preds = %75, %25
  %27 = load i64, ptr %17, align 8, !tbaa !9
  %28 = load i64, ptr %14, align 8, !tbaa !9
  %29 = icmp ult i64 %27, %28
  br i1 %29, label %31, label %30

30:                                               ; preds = %26
  store i32 5, ptr %16, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #3
  br label %78

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

32:                                               ; preds = %61, %31
  %33 = load i64, ptr %19, align 8, !tbaa !9
  %34 = load i64, ptr %12, align 8, !tbaa !9
  %35 = icmp ult i64 %33, %34
  br i1 %35, label %37, label %36

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

37:                                               ; preds = %32
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = load i64, ptr %19, align 8, !tbaa !9
  %40 = load i64, ptr %13, align 8, !tbaa !9
  %41 = mul i64 %39, %40
  %42 = load i64, ptr %15, align 8, !tbaa !9
  %43 = add i64 %41, %42
  %44 = getelementptr inbounds double, ptr %38, i64 %43
  %45 = load double, ptr %44, align 8, !tbaa !11
  %46 = load ptr, ptr %9, align 8, !tbaa !5
  %47 = load i64, ptr %19, align 8, !tbaa !9
  %48 = load i64, ptr %14, align 8, !tbaa !9
  %49 = mul i64 %47, %48
  %50 = load i64, ptr %17, 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 = fmul double %45, %53
  %55 = load ptr, ptr %10, align 8, !tbaa !5
  %56 = load i64, ptr %19, align 8, !tbaa !9
  %57 = getelementptr inbounds double, ptr %55, i64 %56
  %58 = load double, ptr %57, align 8, !tbaa !11
  %59 = load double, ptr %18, align 8, !tbaa !11
  %60 = call double @llvm.fmuladd.f64(double %54, double %58, double %59)
  store double %60, ptr %18, align 8, !tbaa !11
  br label %61

61:                                               ; preds = %37
  %62 = load i64, ptr %19, align 8, !tbaa !9
  %63 = add i64 %62, 1
  store i64 %63, ptr %19, align 8, !tbaa !9
  br label %32, !llvm.loop !13

64:                                               ; preds = %36
  %65 = load double, ptr %18, align 8, !tbaa !11
  %66 = load ptr, ptr %11, align 8, !tbaa !5
  %67 = load i64, ptr %15, align 8, !tbaa !9
  %68 = load i64, ptr %13, align 8, !tbaa !9
  %69 = mul i64 %67, %68
  %70 = load i64, ptr %17, align 8, !tbaa !9
  %71 = add i64 %69, %70
  %72 = getelementptr inbounds double, ptr %66, i64 %71
  %73 = load double, ptr %72, align 8, !tbaa !11
  %74 = fadd double %73, %65
  store double %74, ptr %72, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #3
  br label %75

75:                                               ; preds = %64
  %76 = load i64, ptr %17, align 8, !tbaa !9
  %77 = add i64 %76, 1
  store i64 %77, ptr %17, align 8, !tbaa !9
  br label %26, !llvm.loop !15

78:                                               ; preds = %30
  br label %79

79:                                               ; preds = %78
  %80 = load i64, ptr %15, align 8, !tbaa !9
  %81 = add i64 %80, 1
  store i64 %81, ptr %15, align 8, !tbaa !9
  br label %20, !llvm.loop !16

82:                                               ; preds = %24
  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}
!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: 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 @einsumaa_mn_mp_m__np(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2, ptr nocapture noundef %3, i64 noundef %4, i64 noundef %5, i64 noundef %6) local_unnamed_addr #1 {
  %.not = icmp eq i64 %5, 0
  %.not41 = icmp eq i64 %6, 0
  %or.cond = or i1 %.not, %.not41
  br i1 %or.cond, label %._crit_edge, label %.preheader29.lr.ph.split.us

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

.preheader29.us.us.preheader:                     ; preds = %.preheader29.lr.ph.split.us
  %xtraiter = and i64 %4, 1
  %8 = icmp eq i64 %4, 1
  %unroll_iter = and i64 %4, -2
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader29.us.us

.preheader29.us.preheader:                        ; preds = %.preheader29.lr.ph.split.us
  %min.iters.check = icmp ult i64 %6, 4
  %n.vec = and i64 %6, -4
  %cmp.n = icmp eq i64 %n.vec, %6
  br label %.preheader29.us

.preheader29.us.us:                               ; preds = %.preheader29.us.us.preheader, %._crit_edge35.split.us.us.us
  %.02636.us.us = phi i64 [ %41, %._crit_edge35.split.us.us.us ], [ 0, %.preheader29.us.us.preheader ]
  %invariant.gep.us.us = getelementptr double, ptr %0, i64 %.02636.us.us
  %9 = mul i64 %.02636.us.us, %5
  %10 = getelementptr double, ptr %3, i64 %9
  br label %.preheader.us.us.us

.preheader.us.us.us:                              ; preds = %._crit_edge.us.us.us, %.preheader29.us.us
  %.02534.us.us.us = phi i64 [ 0, %.preheader29.us.us ], [ %40, %._crit_edge.us.us.us ]
  %invariant.gep30.us.us.us = getelementptr double, ptr %1, i64 %.02534.us.us.us
  br i1 %8, 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
  %.033.us.us.us = phi i64 [ %28, %.preheader.us.us.us.new ], [ 0, %.preheader.us.us.us ]
  %.02432.us.us.us = phi double [ %27, %.preheader.us.us.us.new ], [ 0.000000e+00, %.preheader.us.us.us ]
  %niter = phi i64 [ %niter.next.1, %.preheader.us.us.us.new ], [ 0, %.preheader.us.us.us ]
  %11 = mul i64 %.033.us.us.us, %5
  %gep.us.us.us = getelementptr double, ptr %invariant.gep.us.us, i64 %11
  %12 = load double, ptr %gep.us.us.us, align 8, !tbaa !5
  %13 = mul i64 %.033.us.us.us, %6
  %gep31.us.us.us = getelementptr double, ptr %invariant.gep30.us.us.us, i64 %13
  %14 = load double, ptr %gep31.us.us.us, align 8, !tbaa !5
  %15 = fmul double %12, %14
  %16 = getelementptr inbounds double, ptr %2, i64 %.033.us.us.us
  %17 = load double, ptr %16, align 8, !tbaa !5
  %18 = tail call double @llvm.fmuladd.f64(double %15, double %17, double %.02432.us.us.us)
  %19 = or disjoint i64 %.033.us.us.us, 1
  %20 = mul i64 %19, %5
  %gep.us.us.us.1 = getelementptr double, ptr %invariant.gep.us.us, i64 %20
  %21 = load double, ptr %gep.us.us.us.1, align 8, !tbaa !5
  %22 = mul i64 %19, %6
  %gep31.us.us.us.1 = getelementptr double, ptr %invariant.gep30.us.us.us, i64 %22
  %23 = load double, ptr %gep31.us.us.us.1, align 8, !tbaa !5
  %24 = fmul double %21, %23
  %25 = getelementptr inbounds double, ptr %2, i64 %19
  %26 = load double, ptr %25, align 8, !tbaa !5
  %27 = tail call double @llvm.fmuladd.f64(double %24, double %26, double %18)
  %28 = add nuw i64 %.033.us.us.us, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, 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 ], [ %27, %.preheader.us.us.us.new ]
  %.033.us.us.us.unr = phi i64 [ 0, %.preheader.us.us.us ], [ %28, %.preheader.us.us.us.new ]
  %.02432.us.us.us.unr = phi double [ 0.000000e+00, %.preheader.us.us.us ], [ %27, %.preheader.us.us.us.new ]
  br i1 %lcmp.mod.not, label %._crit_edge.us.us.us, label %._crit_edge.us.us.us.epilog-lcssa

._crit_edge.us.us.us.epilog-lcssa:                ; preds = %._crit_edge.us.us.us.unr-lcssa
  %29 = mul i64 %.033.us.us.us.unr, %5
  %gep.us.us.us.epil = getelementptr double, ptr %invariant.gep.us.us, i64 %29
  %30 = load double, ptr %gep.us.us.us.epil, align 8, !tbaa !5
  %31 = mul i64 %.033.us.us.us.unr, %6
  %gep31.us.us.us.epil = getelementptr double, ptr %invariant.gep30.us.us.us, i64 %31
  %32 = load double, ptr %gep31.us.us.us.epil, align 8, !tbaa !5
  %33 = fmul double %30, %32
  %34 = getelementptr inbounds double, ptr %2, i64 %.033.us.us.us.unr
  %35 = load double, ptr %34, align 8, !tbaa !5
  %36 = tail call double @llvm.fmuladd.f64(double %33, double %35, double %.02432.us.us.us.unr)
  br label %._crit_edge.us.us.us

._crit_edge.us.us.us:                             ; preds = %._crit_edge.us.us.us.unr-lcssa, %._crit_edge.us.us.us.epilog-lcssa
  %.lcssa = phi double [ %.lcssa.ph, %._crit_edge.us.us.us.unr-lcssa ], [ %36, %._crit_edge.us.us.us.epilog-lcssa ]
  %37 = getelementptr double, ptr %10, i64 %.02534.us.us.us
  %38 = load double, ptr %37, align 8, !tbaa !5
  %39 = fadd double %.lcssa, %38
  store double %39, ptr %37, align 8, !tbaa !5
  %40 = add nuw i64 %.02534.us.us.us, 1
  %exitcond45.not = icmp eq i64 %40, %6
  br i1 %exitcond45.not, label %._crit_edge35.split.us.us.us, label %.preheader.us.us.us, !llvm.loop !11

._crit_edge35.split.us.us.us:                     ; preds = %._crit_edge.us.us.us
  %41 = add nuw i64 %.02636.us.us, 1
  %exitcond46.not = icmp eq i64 %41, %5
  br i1 %exitcond46.not, label %._crit_edge, label %.preheader29.us.us, !llvm.loop !12

.preheader29.us:                                  ; preds = %.preheader29.us.preheader, %._crit_edge35.split.us39
  %.02636.us = phi i64 [ %53, %._crit_edge35.split.us39 ], [ 0, %.preheader29.us.preheader ]
  %42 = mul i64 %.02636.us, %5
  %43 = getelementptr double, ptr %3, i64 %42
  br i1 %min.iters.check, label %.preheader.us37.preheader, label %vector.body

vector.body:                                      ; preds = %.preheader29.us, %vector.body
  %index = phi i64 [ %index.next, %vector.body ], [ 0, %.preheader29.us ]
  %44 = getelementptr double, ptr %43, i64 %index
  %45 = getelementptr i8, ptr %44, i64 16
  %wide.load = load <2 x double>, ptr %44, align 8, !tbaa !5
  %wide.load51 = load <2 x double>, ptr %45, align 8, !tbaa !5
  %46 = fadd <2 x double> %wide.load, zeroinitializer
  %47 = fadd <2 x double> %wide.load51, zeroinitializer
  store <2 x double> %46, ptr %44, align 8, !tbaa !5
  store <2 x double> %47, ptr %45, align 8, !tbaa !5
  %index.next = add nuw i64 %index, 4
  %48 = icmp eq i64 %index.next, %n.vec
  br i1 %48, label %middle.block, label %vector.body, !llvm.loop !13

middle.block:                                     ; preds = %vector.body
  br i1 %cmp.n, label %._crit_edge35.split.us39, label %.preheader.us37.preheader

.preheader.us37.preheader:                        ; preds = %middle.block, %.preheader29.us
  %.02534.us38.ph = phi i64 [ 0, %.preheader29.us ], [ %n.vec, %middle.block ]
  br label %.preheader.us37

.preheader.us37:                                  ; preds = %.preheader.us37.preheader, %.preheader.us37
  %.02534.us38 = phi i64 [ %52, %.preheader.us37 ], [ %.02534.us38.ph, %.preheader.us37.preheader ]
  %49 = getelementptr double, ptr %43, i64 %.02534.us38
  %50 = load double, ptr %49, align 8, !tbaa !5
  %51 = fadd double %50, 0.000000e+00
  store double %51, ptr %49, align 8, !tbaa !5
  %52 = add nuw i64 %.02534.us38, 1
  %exitcond47.not = icmp eq i64 %52, %6
  br i1 %exitcond47.not, label %._crit_edge35.split.us39, label %.preheader.us37, !llvm.loop !16

._crit_edge35.split.us39:                         ; preds = %.preheader.us37, %middle.block
  %53 = add nuw i64 %.02636.us, 1
  %exitcond48.not = icmp eq i64 %53, %5
  br i1 %exitcond48.not, label %._crit_edge, label %.preheader29.us, !llvm.loop !12

._crit_edge:                                      ; preds = %._crit_edge35.split.us.us.us, %._crit_edge35.split.us39, %7
  ret void
}

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

!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, !10}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10, !14, !15}
!14 = !{!"llvm.loop.isvectorized", i32 1}
!15 = !{!"llvm.loop.unroll.runtime.disable"}
!16 = distinct !{!16, !10, !15, !14}


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