; 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: nounwind uwtable
define dso_local void @transpose(ptr noundef %0, ptr noundef %1, i64 noundef %2, i64 noundef %3) #0 {
  %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
  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 %13

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

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

18:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %19 = load i64, ptr %9, align 8, !tbaa !9
  %20 = load i64, ptr %8, align 8, !tbaa !9
  %21 = mul i64 %19, %20
  store i64 %21, 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 %22

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

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

27:                                               ; preds = %22
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = load i64, ptr %11, align 8, !tbaa !9
  %30 = load i64, ptr %12, align 8, !tbaa !9
  %31 = add i64 %29, %30
  %32 = getelementptr inbounds double, ptr %28, i64 %31
  %33 = load double, ptr %32, align 8, !tbaa !11
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = load i64, ptr %12, align 8, !tbaa !9
  %36 = load i64, ptr %7, align 8, !tbaa !9
  %37 = mul i64 %35, %36
  %38 = load i64, ptr %9, align 8, !tbaa !9
  %39 = add i64 %37, %38
  %40 = getelementptr inbounds double, ptr %34, i64 %39
  store double %33, ptr %40, align 8, !tbaa !11
  br label %41

41:                                               ; preds = %27
  %42 = load i64, ptr %12, align 8, !tbaa !9
  %43 = add i64 %42, 1
  store i64 %43, ptr %12, align 8, !tbaa !9
  br label %22, !llvm.loop !13

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

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

48:                                               ; preds = %17
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 @transpose(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
  %.not21 = icmp eq i64 %3, 0
  %or.cond = or i1 %.not, %.not21
  br i1 %or.cond, label %._crit_edge20, label %.lr.ph.us.preheader

.lr.ph.us.preheader:                              ; preds = %4
  %5 = add i64 %3, %2
  %6 = shl i64 %5, 3
  %7 = getelementptr i8, ptr %1, i64 %6
  %scevgep = getelementptr i8, ptr %7, i64 -8
  %8 = mul i64 %3, %2
  %9 = shl i64 %8, 3
  %scevgep24 = getelementptr i8, ptr %0, i64 %9
  %min.iters.check = icmp ugt i64 %3, 7
  %ident.check.not = icmp eq i64 %2, 1
  %or.cond26 = and i1 %min.iters.check, %ident.check.not
  %bound0 = icmp ugt ptr %scevgep24, %1
  %bound1 = icmp ugt ptr %scevgep, %0
  %found.conflict = and i1 %bound0, %bound1
  %.mask = and i64 %3, 1152921504606846976
  %stride.check = icmp ne i64 %.mask, 0
  %10 = or i1 %found.conflict, %stride.check
  %n.vec = and i64 %3, -1152921504606846980
  %cmp.n = icmp eq i64 %n.vec, %3
  %xtraiter = and i64 %3, 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
  %.01417.us = phi i64 [ %40, %._crit_edge.us ], [ 0, %.lr.ph.us.preheader ]
  %11 = mul i64 %.01417.us, %3
  %invariant.gep.us = getelementptr double, ptr %1, i64 %.01417.us
  %12 = getelementptr double, ptr %0, i64 %11
  %or.cond26.not = xor i1 %or.cond26, true
  %brmerge = or i1 %or.cond26.not, %10
  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 ]
  %13 = getelementptr double, ptr %12, i64 %index
  %14 = getelementptr i8, ptr %13, i64 16
  %wide.load = load <2 x double>, ptr %13, align 8, !tbaa !5, !alias.scope !9
  %wide.load25 = load <2 x double>, ptr %14, align 8, !tbaa !5, !alias.scope !9
  %15 = getelementptr double, ptr %invariant.gep.us, i64 %index
  %16 = getelementptr i8, ptr %15, i64 16
  store <2 x double> %wide.load, ptr %15, align 8, !tbaa !5, !alias.scope !12, !noalias !9
  store <2 x double> %wide.load25, ptr %16, align 8, !tbaa !5, !alias.scope !12, !noalias !9
  %index.next = add nuw i64 %index, 4
  %17 = icmp eq i64 %index.next, %n.vec
  br i1 %17, 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 [ %21, %scalar.ph.prol ], [ %.016.us.ph, %scalar.ph.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %scalar.ph.prol ], [ 0, %scalar.ph.preheader ]
  %18 = getelementptr double, ptr %12, i64 %.016.us.prol
  %19 = load double, ptr %18, align 8, !tbaa !5
  %20 = mul i64 %.016.us.prol, %2
  %gep.us.prol = getelementptr double, ptr %invariant.gep.us, i64 %20
  store double %19, ptr %gep.us.prol, align 8, !tbaa !5
  %21 = 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 ], [ %21, %scalar.ph.prol ]
  %22 = sub i64 %.016.us.ph, %3
  %23 = icmp ugt i64 %22, -4
  br i1 %23, label %._crit_edge.us, label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph
  %.016.us = phi i64 [ %39, %scalar.ph ], [ %.016.us.unr, %scalar.ph.prol.loopexit ]
  %24 = getelementptr double, ptr %12, i64 %.016.us
  %25 = load double, ptr %24, align 8, !tbaa !5
  %26 = mul i64 %.016.us, %2
  %gep.us = getelementptr double, ptr %invariant.gep.us, i64 %26
  store double %25, ptr %gep.us, align 8, !tbaa !5
  %27 = add nuw i64 %.016.us, 1
  %28 = getelementptr double, ptr %12, i64 %27
  %29 = load double, ptr %28, align 8, !tbaa !5
  %30 = mul i64 %27, %2
  %gep.us.1 = getelementptr double, ptr %invariant.gep.us, i64 %30
  store double %29, ptr %gep.us.1, align 8, !tbaa !5
  %31 = add nuw i64 %.016.us, 2
  %32 = getelementptr double, ptr %12, i64 %31
  %33 = load double, ptr %32, align 8, !tbaa !5
  %34 = mul i64 %31, %2
  %gep.us.2 = getelementptr double, ptr %invariant.gep.us, i64 %34
  store double %33, ptr %gep.us.2, align 8, !tbaa !5
  %35 = add nuw i64 %.016.us, 3
  %36 = getelementptr double, ptr %12, i64 %35
  %37 = load double, ptr %36, align 8, !tbaa !5
  %38 = mul i64 %35, %2
  %gep.us.3 = getelementptr double, ptr %invariant.gep.us, i64 %38
  store double %37, ptr %gep.us.3, align 8, !tbaa !5
  %39 = add nuw i64 %.016.us, 4
  %exitcond.not.3 = icmp eq i64 %39, %3
  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
  %40 = add nuw i64 %.01417.us, 1
  %exitcond23.not = icmp eq i64 %40, %2
  br i1 %exitcond23.not, label %._crit_edge20, label %.lr.ph.us, !llvm.loop !21

._crit_edge20:                                    ; 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 = !{!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