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

16:                                               ; preds = %49, %5
  %17 = load i64, ptr %11, align 8, !tbaa !9
  %18 = load i64, ptr %9, align 8, !tbaa !9
  %19 = icmp ult i64 %17, %18
  br i1 %19, label %21, label %20

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

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

28:                                               ; preds = %45, %21
  %29 = load i64, ptr %15, align 8, !tbaa !9
  %30 = load i64, ptr %10, align 8, !tbaa !9
  %31 = icmp ult i64 %29, %30
  br i1 %31, label %33, label %32

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

33:                                               ; preds = %28
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = load i64, ptr %14, align 8, !tbaa !9
  %36 = load i64, ptr %15, align 8, !tbaa !9
  %37 = add i64 %35, %36
  %38 = getelementptr inbounds double, ptr %34, i64 %37
  %39 = load double, ptr %38, align 8, !tbaa !11
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = load i64, ptr %13, align 8, !tbaa !9
  %42 = load i64, ptr %15, align 8, !tbaa !9
  %43 = add i64 %41, %42
  %44 = getelementptr inbounds double, ptr %40, i64 %43
  store double %39, ptr %44, align 8, !tbaa !11
  br label %45

45:                                               ; preds = %33
  %46 = load i64, ptr %15, align 8, !tbaa !9
  %47 = add i64 %46, 1
  store i64 %47, ptr %15, align 8, !tbaa !9
  br label %28, !llvm.loop !13

48:                                               ; preds = %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #2
  br label %49

49:                                               ; preds = %48
  %50 = load i64, ptr %11, align 8, !tbaa !9
  %51 = add i64 %50, 1
  store i64 %51, ptr %11, align 8, !tbaa !9
  br label %16, !llvm.loop !15

52:                                               ; preds = %20
  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 @matslice(ptr nocapture noundef readonly %0, ptr nocapture noundef writeonly %1, i64 noundef %2, i64 noundef %3, i64 noundef %4) local_unnamed_addr #0 {
  %.not = icmp eq i64 %3, 0
  %.not21 = icmp eq i64 %4, 0
  %or.cond = or i1 %.not, %.not21
  br i1 %or.cond, label %._crit_edge20, label %.lr.ph.us.preheader

.lr.ph.us.preheader:                              ; preds = %5
  %6 = mul i64 %4, %3
  %7 = shl i64 %6, 3
  %scevgep = getelementptr i8, ptr %1, i64 %7
  %8 = add i64 %3, 2305843009213693951
  %9 = mul i64 %8, %2
  %10 = add i64 %9, %4
  %11 = shl i64 %10, 3
  %scevgep25 = getelementptr i8, ptr %0, i64 %11
  %min.iters.check = icmp ult i64 %4, 8
  %bound0 = icmp ugt ptr %scevgep25, %1
  %bound1 = icmp ugt ptr %scevgep, %0
  %found.conflict = and i1 %bound0, %bound1
  %12 = or i64 %4, %2
  %13 = and i64 %12, 1152921504606846976
  %14 = icmp ne i64 %13, 0
  %15 = or i1 %found.conflict, %14
  %n.vec = and i64 %4, -4
  %cmp.n = icmp eq i64 %n.vec, %4
  %xtraiter = and i64 %4, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.lr.ph.us

.lr.ph.us:                                        ; preds = %.lr.ph.us.preheader, %._crit_edge.us
  %.01517.us = phi i64 [ %47, %._crit_edge.us ], [ 0, %.lr.ph.us.preheader ]
  %16 = mul i64 %.01517.us, %4
  %17 = mul i64 %.01517.us, %2
  %18 = getelementptr double, ptr %0, i64 %17
  %19 = getelementptr double, ptr %1, i64 %16
  %brmerge = select i1 %min.iters.check, i1 true, i1 %15
  br i1 %brmerge, label %scalar.ph.preheader, label %vector.body

vector.body:                                      ; preds = %.lr.ph.us, %vector.body
  %index = phi i64 [ %index.next, %vector.body ], [ 0, %.lr.ph.us ]
  %20 = getelementptr double, ptr %18, i64 %index
  %21 = getelementptr i8, ptr %20, i64 16
  %wide.load = load <2 x double>, ptr %20, align 8, !tbaa !5, !alias.scope !9
  %wide.load27 = load <2 x double>, ptr %21, align 8, !tbaa !5, !alias.scope !9
  %22 = getelementptr double, ptr %19, i64 %index
  %23 = getelementptr i8, ptr %22, i64 16
  store <2 x double> %wide.load, ptr %22, align 8, !tbaa !5, !alias.scope !12, !noalias !9
  store <2 x double> %wide.load27, ptr %23, align 8, !tbaa !5, !alias.scope !12, !noalias !9
  %index.next = add nuw i64 %index, 4
  %24 = icmp eq i64 %index.next, %n.vec
  br i1 %24, label %middle.block, label %vector.body, !llvm.loop !14

middle.block:                                     ; preds = %vector.body
  br i1 %cmp.n, label %._crit_edge.us, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %.lr.ph.us, %middle.block
  %.016.us.ph = phi i64 [ 0, %.lr.ph.us ], [ %n.vec, %middle.block ]
  br i1 %lcmp.mod.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol

scalar.ph.prol:                                   ; preds = %scalar.ph.preheader, %scalar.ph.prol
  %.016.us.prol = phi i64 [ %28, %scalar.ph.prol ], [ %.016.us.ph, %scalar.ph.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %scalar.ph.prol ], [ 0, %scalar.ph.preheader ]
  %25 = getelementptr double, ptr %18, i64 %.016.us.prol
  %26 = load double, ptr %25, align 8, !tbaa !5
  %27 = getelementptr double, ptr %19, i64 %.016.us.prol
  store double %26, ptr %27, align 8, !tbaa !5
  %28 = add nuw i64 %.016.us.prol, 1
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol, !llvm.loop !18

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol, %scalar.ph.preheader
  %.016.us.unr = phi i64 [ %.016.us.ph, %scalar.ph.preheader ], [ %28, %scalar.ph.prol ]
  %29 = sub i64 %.016.us.ph, %4
  %30 = icmp ugt i64 %29, -4
  br i1 %30, label %._crit_edge.us, label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph
  %.016.us = phi i64 [ %46, %scalar.ph ], [ %.016.us.unr, %scalar.ph.prol.loopexit ]
  %31 = getelementptr double, ptr %18, i64 %.016.us
  %32 = load double, ptr %31, align 8, !tbaa !5
  %33 = getelementptr double, ptr %19, i64 %.016.us
  store double %32, ptr %33, align 8, !tbaa !5
  %34 = add nuw i64 %.016.us, 1
  %35 = getelementptr double, ptr %18, i64 %34
  %36 = load double, ptr %35, align 8, !tbaa !5
  %37 = getelementptr double, ptr %19, i64 %34
  store double %36, ptr %37, align 8, !tbaa !5
  %38 = add nuw i64 %.016.us, 2
  %39 = getelementptr double, ptr %18, i64 %38
  %40 = load double, ptr %39, align 8, !tbaa !5
  %41 = getelementptr double, ptr %19, i64 %38
  store double %40, ptr %41, align 8, !tbaa !5
  %42 = add nuw i64 %.016.us, 3
  %43 = getelementptr double, ptr %18, i64 %42
  %44 = load double, ptr %43, align 8, !tbaa !5
  %45 = getelementptr double, ptr %19, i64 %42
  store double %44, ptr %45, align 8, !tbaa !5
  %46 = add nuw i64 %.016.us, 4
  %exitcond.not.3 = icmp eq i64 %46, %4
  br i1 %exitcond.not.3, label %._crit_edge.us, label %scalar.ph, !llvm.loop !20

._crit_edge.us:                                   ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block
  %47 = add nuw i64 %.01517.us, 1
  %exitcond24.not = icmp eq i64 %47, %3
  br i1 %exitcond24.not, label %._crit_edge20, label %.lr.ph.us, !llvm.loop !21

._crit_edge20:                                    ; preds = %._crit_edge.us, %5
  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 = !{!10}
!10 = distinct !{!10, !11}
!11 = distinct !{!11, !"LVerDomain"}
!12 = !{!13}
!13 = distinct !{!13, !11}
!14 = distinct !{!14, !15, !16, !17}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!"llvm.loop.isvectorized", i32 1}
!17 = !{!"llvm.loop.unroll.runtime.disable"}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.unroll.disable"}
!20 = distinct !{!20, !15, !16}
!21 = distinct !{!21, !15}


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