; LLVM IR from microsoft/LightAIMD :: src (matrix)

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

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

14:                                               ; preds = %52, %4
  %15 = load i64, ptr %9, align 8, !tbaa !9
  %16 = load i64, ptr %7, align 8, !tbaa !9
  %17 = icmp ult i64 %15, %16
  br i1 %17, label %19, label %18

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

19:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %20 = load i64, ptr %9, align 8, !tbaa !9
  %21 = load i64, ptr %8, align 8, !tbaa !9
  %22 = mul i64 %20, %21
  store i64 %22, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  store i64 0, ptr %12, align 8, !tbaa !9
  br label %23

23:                                               ; preds = %48, %19
  %24 = load i64, ptr %12, align 8, !tbaa !9
  %25 = load i64, ptr %8, align 8, !tbaa !9
  %26 = icmp ult i64 %24, %25
  br i1 %26, label %28, label %27

27:                                               ; preds = %23
  store i32 5, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  br label %51

28:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #2
  %29 = load i64, ptr %11, align 8, !tbaa !9
  %30 = load i64, ptr %12, align 8, !tbaa !9
  %31 = add i64 %29, %30
  store i64 %31, ptr %13, align 8, !tbaa !9
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = load i64, ptr %13, align 8, !tbaa !9
  %34 = getelementptr inbounds double, ptr %32, i64 %33
  %35 = load double, ptr %34, align 8, !tbaa !11
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = load i64, ptr %12, align 8, !tbaa !9
  %38 = load i64, ptr %8, align 8, !tbaa !9
  %39 = mul i64 %37, %38
  %40 = load i64, ptr %9, align 8, !tbaa !9
  %41 = add i64 %39, %40
  %42 = getelementptr inbounds double, ptr %36, i64 %41
  %43 = load double, ptr %42, align 8, !tbaa !11
  %44 = fadd double %35, %43
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = load i64, ptr %13, align 8, !tbaa !9
  %47 = getelementptr inbounds double, ptr %45, i64 %46
  store double %44, ptr %47, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #2
  br label %48

48:                                               ; preds = %28
  %49 = load i64, ptr %12, align 8, !tbaa !9
  %50 = add i64 %49, 1
  store i64 %50, ptr %12, align 8, !tbaa !9
  br label %23, !llvm.loop !13

51:                                               ; preds = %27
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  br label %52

52:                                               ; preds = %51
  %53 = load i64, ptr %9, align 8, !tbaa !9
  %54 = add i64 %53, 1
  store i64 %54, ptr %9, align 8, !tbaa !9
  br label %14, !llvm.loop !15

55:                                               ; preds = %18
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = !{!"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: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @mat_add_A_AT(ptr nocapture noundef readonly %0, ptr nocapture noundef writeonly %1, i64 noundef %2, i64 noundef %3) local_unnamed_addr #0 {
  %.not = icmp eq i64 %2, 0
  %.not24 = icmp eq i64 %3, 0
  %or.cond = or i1 %.not, %.not24
  br i1 %or.cond, label %._crit_edge23, label %.lr.ph.us.preheader

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

.lr.ph.us:                                        ; preds = %.lr.ph.us.preheader, %._crit_edge.us
  %.020.us = phi i64 [ %30, %._crit_edge.us ], [ 0, %.lr.ph.us.preheader ]
  %6 = mul i64 %.020.us, %3
  %invariant.gep.us = getelementptr double, ptr %0, i64 %.020.us
  br i1 %5, label %._crit_edge.us.unr-lcssa, label %.lr.ph.us.new

.lr.ph.us.new:                                    ; preds = %.lr.ph.us, %.lr.ph.us.new
  %.01719.us = phi i64 [ %22, %.lr.ph.us.new ], [ 0, %.lr.ph.us ]
  %niter = phi i64 [ %niter.next.1, %.lr.ph.us.new ], [ 0, %.lr.ph.us ]
  %7 = add i64 %.01719.us, %6
  %8 = getelementptr inbounds double, ptr %0, i64 %7
  %9 = load double, ptr %8, align 8, !tbaa !5
  %10 = mul i64 %.01719.us, %3
  %gep.us = getelementptr double, ptr %invariant.gep.us, i64 %10
  %11 = load double, ptr %gep.us, align 8, !tbaa !5
  %12 = fadd double %9, %11
  %13 = getelementptr inbounds double, ptr %1, i64 %7
  store double %12, ptr %13, align 8, !tbaa !5
  %14 = or disjoint i64 %.01719.us, 1
  %15 = add i64 %14, %6
  %16 = getelementptr inbounds double, ptr %0, i64 %15
  %17 = load double, ptr %16, align 8, !tbaa !5
  %18 = mul i64 %14, %3
  %gep.us.1 = getelementptr double, ptr %invariant.gep.us, i64 %18
  %19 = load double, ptr %gep.us.1, align 8, !tbaa !5
  %20 = fadd double %17, %19
  %21 = getelementptr inbounds double, ptr %1, i64 %15
  store double %20, ptr %21, align 8, !tbaa !5
  %22 = add nuw i64 %.01719.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 %.lr.ph.us.new, !llvm.loop !9

._crit_edge.us.unr-lcssa:                         ; preds = %.lr.ph.us.new, %.lr.ph.us
  %.01719.us.unr = phi i64 [ 0, %.lr.ph.us ], [ %22, %.lr.ph.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
  %23 = add i64 %.01719.us.unr, %6
  %24 = getelementptr inbounds double, ptr %0, i64 %23
  %25 = load double, ptr %24, align 8, !tbaa !5
  %26 = mul i64 %.01719.us.unr, %3
  %gep.us.epil = getelementptr double, ptr %invariant.gep.us, i64 %26
  %27 = load double, ptr %gep.us.epil, align 8, !tbaa !5
  %28 = fadd double %25, %27
  %29 = getelementptr inbounds double, ptr %1, i64 %23
  store double %28, ptr %29, align 8, !tbaa !5
  br label %._crit_edge.us

._crit_edge.us:                                   ; preds = %._crit_edge.us.unr-lcssa, %._crit_edge.us.epilog-lcssa
  %30 = add nuw i64 %.020.us, 1
  %exitcond26.not = icmp eq i64 %30, %2
  br i1 %exitcond26.not, label %._crit_edge23, label %.lr.ph.us, !llvm.loop !11

._crit_edge23:                                    ; 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


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