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

12:                                               ; preds = %39, %3
  %13 = load i64, ptr %8, align 8, !tbaa !9
  %14 = load i64, ptr %5, align 8, !tbaa !9
  %15 = icmp ult i64 %13, %14
  br i1 %15, label %17, label %16

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

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

21:                                               ; preds = %35, %17
  %22 = load i64, ptr %11, align 8, !tbaa !9
  %23 = load i64, ptr %6, align 8, !tbaa !9
  %24 = icmp ult i64 %22, %23
  br i1 %24, label %26, label %25

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

26:                                               ; preds = %21
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = load i64, ptr %10, align 8, !tbaa !9
  %29 = load i64, ptr %11, align 8, !tbaa !9
  %30 = add i64 %28, %29
  %31 = getelementptr inbounds double, ptr %27, i64 %30
  %32 = load double, ptr %31, align 8, !tbaa !11
  %33 = load double, ptr %7, align 8, !tbaa !11
  %34 = fadd double %33, %32
  store double %34, ptr %7, align 8, !tbaa !11
  br label %35

35:                                               ; preds = %26
  %36 = load i64, ptr %11, align 8, !tbaa !9
  %37 = add i64 %36, 1
  store i64 %37, ptr %11, align 8, !tbaa !9
  br label %21, !llvm.loop !13

38:                                               ; preds = %25
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  br label %39

39:                                               ; preds = %38
  %40 = load i64, ptr %8, align 8, !tbaa !9
  %41 = add i64 %40, 1
  store i64 %41, ptr %8, align 8, !tbaa !9
  br label %12, !llvm.loop !15

42:                                               ; preds = %16
  %43 = load double, ptr %7, align 8, !tbaa !11
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret double %43
}

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: read) uwtable
define dso_local double @matsum(ptr nocapture noundef readonly %0, i64 noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %.not = icmp eq i64 %1, 0
  %.not22 = icmp eq i64 %2, 0
  %or.cond = or i1 %.not, %.not22
  br i1 %or.cond, label %._crit_edge20, label %.lr.ph.us.preheader

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

.lr.ph.us:                                        ; preds = %.lr.ph.us.preheader, %._crit_edge.us
  %.01217.us = phi double [ %.lcssa, %._crit_edge.us ], [ 0.000000e+00, %.lr.ph.us.preheader ]
  %.01316.us = phi i64 [ %44, %._crit_edge.us ], [ 0, %.lr.ph.us.preheader ]
  %6 = mul i64 %.01316.us, %2
  %7 = getelementptr double, ptr %0, i64 %6
  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
  %.015.us = phi i64 [ %39, %.lr.ph.us.new ], [ 0, %.lr.ph.us ]
  %.114.us = phi double [ %38, %.lr.ph.us.new ], [ %.01217.us, %.lr.ph.us ]
  %niter = phi i64 [ %niter.next.7, %.lr.ph.us.new ], [ 0, %.lr.ph.us ]
  %8 = getelementptr double, ptr %7, i64 %.015.us
  %9 = load double, ptr %8, align 8, !tbaa !5
  %10 = fadd double %.114.us, %9
  %11 = or disjoint i64 %.015.us, 1
  %12 = getelementptr double, ptr %7, i64 %11
  %13 = load double, ptr %12, align 8, !tbaa !5
  %14 = fadd double %10, %13
  %15 = or disjoint i64 %.015.us, 2
  %16 = getelementptr double, ptr %7, i64 %15
  %17 = load double, ptr %16, align 8, !tbaa !5
  %18 = fadd double %14, %17
  %19 = or disjoint i64 %.015.us, 3
  %20 = getelementptr double, ptr %7, i64 %19
  %21 = load double, ptr %20, align 8, !tbaa !5
  %22 = fadd double %18, %21
  %23 = or disjoint i64 %.015.us, 4
  %24 = getelementptr double, ptr %7, i64 %23
  %25 = load double, ptr %24, align 8, !tbaa !5
  %26 = fadd double %22, %25
  %27 = or disjoint i64 %.015.us, 5
  %28 = getelementptr double, ptr %7, i64 %27
  %29 = load double, ptr %28, align 8, !tbaa !5
  %30 = fadd double %26, %29
  %31 = or disjoint i64 %.015.us, 6
  %32 = getelementptr double, ptr %7, i64 %31
  %33 = load double, ptr %32, align 8, !tbaa !5
  %34 = fadd double %30, %33
  %35 = or disjoint i64 %.015.us, 7
  %36 = getelementptr double, ptr %7, i64 %35
  %37 = load double, ptr %36, align 8, !tbaa !5
  %38 = fadd double %34, %37
  %39 = add nuw i64 %.015.us, 8
  %niter.next.7 = add i64 %niter, 8
  %niter.ncmp.7 = icmp eq i64 %niter.next.7, %unroll_iter
  br i1 %niter.ncmp.7, 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 ], [ %38, %.lr.ph.us.new ]
  %.015.us.unr = phi i64 [ 0, %.lr.ph.us ], [ %39, %.lr.ph.us.new ]
  %.114.us.unr = phi double [ %.01217.us, %.lr.ph.us ], [ %38, %.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
  %.015.us.epil = phi i64 [ %43, %.epil.preheader ], [ %.015.us.unr, %._crit_edge.us.unr-lcssa ]
  %.114.us.epil = phi double [ %42, %.epil.preheader ], [ %.114.us.unr, %._crit_edge.us.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %._crit_edge.us.unr-lcssa ]
  %40 = getelementptr double, ptr %7, i64 %.015.us.epil
  %41 = load double, ptr %40, align 8, !tbaa !5
  %42 = fadd double %.114.us.epil, %41
  %43 = add nuw i64 %.015.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 = add nuw i64 %.01316.us, 1
  %exitcond24.not = icmp eq i64 %44, %1
  br i1 %exitcond24.not, label %._crit_edge20, label %.lr.ph.us, !llvm.loop !13

._crit_edge20:                                    ; preds = %._crit_edge.us, %3
  %.012.lcssa = phi double [ 0.000000e+00, %3 ], [ %.lcssa, %._crit_edge.us ]
  ret double %.012.lcssa
}

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: read) 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, !12}
!12 = !{!"llvm.loop.unroll.disable"}
!13 = distinct !{!13, !10}


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