; LLVM IR from microsoft/LightAIMD :: src/einsum.ll_task_func_einsum_mn_mp (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"

%struct.task_func_einsum_mn_mp__np_arg = type { ptr, ptr, ptr, i64, i64, i64, i64 }

; 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

declare void @x_free(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @task_func_einsum_mn_mp__np(ptr noundef %0) #3 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  %6 = alloca double, align 8
  %7 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %8, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  store i64 0, ptr %4, align 8, !tbaa !9
  br label %9

9:                                                ; preds = %71, %1
  %10 = load i64, ptr %4, align 8, !tbaa !9
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.task_func_einsum_mn_mp__np_arg, ptr %11, i32 0, i32 5
  %13 = load i64, ptr %12, align 8, !tbaa !11
  %14 = icmp ult i64 %10, %13
  br i1 %14, label %16, label %15

15:                                               ; preds = %9
  store i32 2, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  br label %74

16:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  store double 0.000000e+00, ptr %6, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store i64 0, ptr %7, align 8, !tbaa !9
  br label %17

17:                                               ; preds = %53, %16
  %18 = load i64, ptr %7, align 8, !tbaa !9
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.task_func_einsum_mn_mp__np_arg, ptr %19, i32 0, i32 3
  %21 = load i64, ptr %20, align 8, !tbaa !15
  %22 = icmp ult i64 %18, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %17
  store i32 5, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  br label %56

24:                                               ; preds = %17
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.task_func_einsum_mn_mp__np_arg, ptr %25, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !16
  %28 = load i64, ptr %7, align 8, !tbaa !9
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.task_func_einsum_mn_mp__np_arg, ptr %29, i32 0, i32 4
  %31 = load i64, ptr %30, align 8, !tbaa !17
  %32 = mul i64 %28, %31
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.task_func_einsum_mn_mp__np_arg, ptr %33, i32 0, i32 6
  %35 = load i64, ptr %34, align 8, !tbaa !18
  %36 = add i64 %32, %35
  %37 = getelementptr inbounds double, ptr %27, i64 %36
  %38 = load double, ptr %37, align 8, !tbaa !13
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.task_func_einsum_mn_mp__np_arg, ptr %39, i32 0, i32 1
  %41 = load ptr, ptr %40, align 8, !tbaa !19
  %42 = load i64, ptr %7, align 8, !tbaa !9
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.task_func_einsum_mn_mp__np_arg, ptr %43, i32 0, i32 5
  %45 = load i64, ptr %44, align 8, !tbaa !11
  %46 = mul i64 %42, %45
  %47 = load i64, ptr %4, align 8, !tbaa !9
  %48 = add i64 %46, %47
  %49 = getelementptr inbounds double, ptr %41, i64 %48
  %50 = load double, ptr %49, align 8, !tbaa !13
  %51 = load double, ptr %6, align 8, !tbaa !13
  %52 = call double @llvm.fmuladd.f64(double %38, double %50, double %51)
  store double %52, ptr %6, align 8, !tbaa !13
  br label %53

53:                                               ; preds = %24
  %54 = load i64, ptr %7, align 8, !tbaa !9
  %55 = add i64 %54, 1
  store i64 %55, ptr %7, align 8, !tbaa !9
  br label %17, !llvm.loop !20

56:                                               ; preds = %23
  %57 = load double, ptr %6, align 8, !tbaa !13
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.task_func_einsum_mn_mp__np_arg, ptr %58, i32 0, i32 2
  %60 = load ptr, ptr %59, align 8, !tbaa !22
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.task_func_einsum_mn_mp__np_arg, ptr %61, i32 0, i32 6
  %63 = load i64, ptr %62, align 8, !tbaa !18
  %64 = load ptr, ptr %3, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.task_func_einsum_mn_mp__np_arg, ptr %64, i32 0, i32 4
  %66 = load i64, ptr %65, align 8, !tbaa !17
  %67 = mul i64 %63, %66
  %68 = load i64, ptr %4, align 8, !tbaa !9
  %69 = add i64 %67, %68
  %70 = getelementptr inbounds double, ptr %60, i64 %69
  store double %57, ptr %70, align 8, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %71

71:                                               ; preds = %56
  %72 = load i64, ptr %4, align 8, !tbaa !9
  %73 = add i64 %72, 1
  store i64 %73, ptr %4, align 8, !tbaa !9
  br label %9, !llvm.loop !23

74:                                               ; preds = %15
  %75 = load ptr, ptr %2, align 8, !tbaa !5
  call void @x_free(ptr noundef %75)
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { "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 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 #4 = { 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, !10, i64 40}
!12 = !{!"task_func_einsum_mn_mp__np_arg", !6, i64 0, !6, i64 8, !6, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48}
!13 = !{!14, !14, i64 0}
!14 = !{!"double", !7, i64 0}
!15 = !{!12, !10, i64 24}
!16 = !{!12, !6, i64 0}
!17 = !{!12, !10, i64 32}
!18 = !{!12, !10, i64 48}
!19 = !{!12, !6, i64 8}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!12, !6, i64 16}
!23 = distinct !{!23, !21}


; 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

declare void @x_free(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @task_func_einsum_mn_mp__np(ptr noundef %0) local_unnamed_addr #2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 40
  %3 = load i64, ptr %2, align 8, !tbaa !5
  %.not = icmp eq i64 %3, 0
  br i1 %.not, label %._crit_edge28, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 24
  %5 = load i64, ptr %4, align 8, !tbaa !11
  %.not29 = icmp eq i64 %5, 0
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  %7 = load ptr, ptr %6, align 8, !tbaa !12
  %8 = getelementptr inbounds i8, ptr %0, i64 48
  %9 = load i64, ptr %8, align 8, !tbaa !13
  %10 = getelementptr inbounds i8, ptr %0, i64 32
  %11 = load i64, ptr %10, align 8, !tbaa !14
  %12 = mul i64 %11, %9
  %13 = getelementptr double, ptr %7, i64 %12
  br i1 %.not29, label %.preheader.preheader, label %.preheader.lr.ph.split.us

.preheader.preheader:                             ; preds = %.preheader.lr.ph
  %14 = shl nuw i64 %3, 3
  tail call void @llvm.memset.p0.i64(ptr align 8 %13, i8 0, i64 %14, i1 false), !tbaa !15
  br label %._crit_edge28

.preheader.lr.ph.split.us:                        ; preds = %.preheader.lr.ph
  %15 = getelementptr inbounds i8, ptr %0, i64 8
  %16 = load ptr, ptr %0, align 8, !tbaa !17
  %invariant.gep.us = getelementptr double, ptr %16, i64 %9
  %17 = load ptr, ptr %15, align 8, !tbaa !18
  %xtraiter = and i64 %5, 1
  %18 = icmp eq i64 %5, 1
  %unroll_iter = and i64 %5, -2
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader.us

.preheader.us:                                    ; preds = %._crit_edge.us, %.preheader.lr.ph.split.us
  %.02227.us = phi i64 [ 0, %.preheader.lr.ph.split.us ], [ %37, %._crit_edge.us ]
  %invariant.gep25.us = getelementptr double, ptr %17, i64 %.02227.us
  br i1 %18, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new

.preheader.us.new:                                ; preds = %.preheader.us, %.preheader.us.new
  %.024.us = phi i64 [ %30, %.preheader.us.new ], [ 0, %.preheader.us ]
  %.02123.us = phi double [ %29, %.preheader.us.new ], [ 0.000000e+00, %.preheader.us ]
  %niter = phi i64 [ %niter.next.1, %.preheader.us.new ], [ 0, %.preheader.us ]
  %19 = mul i64 %11, %.024.us
  %gep.us = getelementptr double, ptr %invariant.gep.us, i64 %19
  %20 = load double, ptr %gep.us, align 8, !tbaa !15
  %21 = mul i64 %.024.us, %3
  %gep26.us = getelementptr double, ptr %invariant.gep25.us, i64 %21
  %22 = load double, ptr %gep26.us, align 8, !tbaa !15
  %23 = tail call double @llvm.fmuladd.f64(double %20, double %22, double %.02123.us)
  %24 = or disjoint i64 %.024.us, 1
  %25 = mul i64 %11, %24
  %gep.us.1 = getelementptr double, ptr %invariant.gep.us, i64 %25
  %26 = load double, ptr %gep.us.1, align 8, !tbaa !15
  %27 = mul i64 %24, %3
  %gep26.us.1 = getelementptr double, ptr %invariant.gep25.us, i64 %27
  %28 = load double, ptr %gep26.us.1, align 8, !tbaa !15
  %29 = tail call double @llvm.fmuladd.f64(double %26, double %28, double %23)
  %30 = add nuw i64 %.024.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.unr-lcssa, label %.preheader.us.new, !llvm.loop !19

._crit_edge.us.unr-lcssa:                         ; preds = %.preheader.us.new, %.preheader.us
  %.lcssa.ph = phi double [ poison, %.preheader.us ], [ %29, %.preheader.us.new ]
  %.024.us.unr = phi i64 [ 0, %.preheader.us ], [ %30, %.preheader.us.new ]
  %.02123.us.unr = phi double [ 0.000000e+00, %.preheader.us ], [ %29, %.preheader.us.new ]
  br i1 %lcmp.mod.not, label %._crit_edge.us, label %._crit_edge.us.epilog-lcssa

._crit_edge.us.epilog-lcssa:                      ; preds = %._crit_edge.us.unr-lcssa
  %31 = mul i64 %11, %.024.us.unr
  %gep.us.epil = getelementptr double, ptr %invariant.gep.us, i64 %31
  %32 = load double, ptr %gep.us.epil, align 8, !tbaa !15
  %33 = mul i64 %.024.us.unr, %3
  %gep26.us.epil = getelementptr double, ptr %invariant.gep25.us, i64 %33
  %34 = load double, ptr %gep26.us.epil, align 8, !tbaa !15
  %35 = tail call double @llvm.fmuladd.f64(double %32, double %34, double %.02123.us.unr)
  br label %._crit_edge.us

._crit_edge.us:                                   ; preds = %._crit_edge.us.unr-lcssa, %._crit_edge.us.epilog-lcssa
  %.lcssa = phi double [ %.lcssa.ph, %._crit_edge.us.unr-lcssa ], [ %35, %._crit_edge.us.epilog-lcssa ]
  %36 = getelementptr double, ptr %13, i64 %.02227.us
  store double %.lcssa, ptr %36, align 8, !tbaa !15
  %37 = add nuw i64 %.02227.us, 1
  %exitcond31.not = icmp eq i64 %37, %3
  br i1 %exitcond31.not, label %._crit_edge28, label %.preheader.us, !llvm.loop !21

._crit_edge28:                                    ; preds = %._crit_edge.us, %.preheader.preheader, %1
  tail call void @x_free(ptr noundef nonnull %0) #4
  ret void
}

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { "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 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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, !10, i64 40}
!6 = !{!"task_func_einsum_mn_mp__np_arg", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !10, i64 24}
!12 = !{!6, !7, i64 16}
!13 = !{!6, !10, i64 48}
!14 = !{!6, !10, i64 32}
!15 = !{!16, !16, i64 0}
!16 = !{!"double", !8, i64 0}
!17 = !{!6, !7, i64 0}
!18 = !{!6, !7, i64 8}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = distinct !{!21, !20}


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