; LLVM IR from NVIDIA/tensorflow :: tensorflow/lite/toco/tensorflow_graph_matching (cluster_utils)

; 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: mustprogress nounwind uwtable
define dso_local void @_ZN4toco17Transpose2DTensorEPKfiiPf(ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %13 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %13, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %14

14:                                               ; preds = %41, %4
  %15 = load i32, ptr %10, align 4, !tbaa !9
  %16 = load i32, ptr %6, align 4, !tbaa !9
  %17 = icmp slt i32 %15, %16
  br i1 %17, label %19, label %18

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

19:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  store i32 0, ptr %12, align 4, !tbaa !9
  br label %20

20:                                               ; preds = %35, %19
  %21 = load i32, ptr %12, align 4, !tbaa !9
  %22 = load i32, ptr %7, align 4, !tbaa !9
  %23 = icmp slt i32 %21, %22
  br i1 %23, label %25, label %24

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

25:                                               ; preds = %20
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds float, ptr %26, i32 1
  store ptr %27, ptr %5, align 8, !tbaa !5
  %28 = load float, ptr %26, align 4, !tbaa !11
  %29 = load ptr, ptr %9, align 8, !tbaa !5
  %30 = load i32, ptr %12, align 4, !tbaa !9
  %31 = load i32, ptr %6, align 4, !tbaa !9
  %32 = mul nsw i32 %30, %31
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds float, ptr %29, i64 %33
  store float %28, ptr %34, align 4, !tbaa !11
  br label %35

35:                                               ; preds = %25
  %36 = load i32, ptr %12, align 4, !tbaa !9
  %37 = add nsw i32 %36, 1
  store i32 %37, ptr %12, align 4, !tbaa !9
  br label %20, !llvm.loop !13

38:                                               ; preds = %24
  %39 = load ptr, ptr %9, align 8, !tbaa !5
  %40 = getelementptr inbounds float, ptr %39, i32 1
  store ptr %40, ptr %9, align 8, !tbaa !5
  br label %41

41:                                               ; preds = %38
  %42 = load i32, ptr %10, align 4, !tbaa !9
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %10, align 4, !tbaa !9
  br label %14, !llvm.loop !15

44:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  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 = { mustprogress 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !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: mustprogress nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @_ZN4toco17Transpose2DTensorEPKfiiPf(ptr nocapture noundef readonly %0, i32 noundef %1, i32 noundef %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #0 {
  %5 = ptrtoint ptr %3 to i64
  %6 = icmp sgt i32 %1, 0
  %7 = icmp sgt i32 %2, 0
  %or.cond = and i1 %6, %7
  br i1 %or.cond, label %.preheader.us.preheader, label %._crit_edge20

.preheader.us.preheader:                          ; preds = %4
  %8 = zext nneg i32 %1 to i64
  %wide.trip.count = zext nneg i32 %2 to i64
  %min.iters.check = icmp ult i32 %2, 8
  %ident.check.not = icmp ne i32 %1, 1
  %or.cond28.not30 = or i1 %min.iters.check, %ident.check.not
  %n.vec = and i64 %wide.trip.count, 2147483640
  %9 = shl nuw nsw i64 %n.vec, 2
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  %xtraiter = and i64 %wide.trip.count, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %indvar = phi i64 [ 0, %.preheader.us.preheader ], [ %indvar.next, %._crit_edge.us ]
  %.01119.us = phi i32 [ 0, %.preheader.us.preheader ], [ %40, %._crit_edge.us ]
  %.01218.us = phi ptr [ %3, %.preheader.us.preheader ], [ %39, %._crit_edge.us ]
  %.01317.us = phi ptr [ %0, %.preheader.us.preheader ], [ %.lcssa, %._crit_edge.us ]
  %10 = shl nuw nsw i64 %indvar, 2
  %11 = add i64 %10, %5
  %.01317.us24 = ptrtoint ptr %.01317.us to i64
  %12 = sub i64 %11, %.01317.us24
  %diff.check = icmp ult i64 %12, 32
  %or.cond29 = select i1 %or.cond28.not30, i1 true, i1 %diff.check
  br i1 %or.cond29, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %.preheader.us
  %ind.end = getelementptr i8, ptr %.01317.us, i64 %9
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %offset.idx = shl i64 %index, 2
  %next.gep = getelementptr i8, ptr %.01317.us, i64 %offset.idx
  %13 = getelementptr i8, ptr %next.gep, i64 16
  %wide.load = load <4 x float>, ptr %next.gep, align 4, !tbaa !5
  %wide.load27 = load <4 x float>, ptr %13, align 4, !tbaa !5
  %14 = getelementptr inbounds float, ptr %.01218.us, i64 %index
  %15 = getelementptr inbounds i8, ptr %14, i64 16
  store <4 x float> %wide.load, ptr %14, align 4, !tbaa !5
  store <4 x float> %wide.load27, ptr %15, align 4, !tbaa !5
  %index.next = add nuw i64 %index, 8
  %16 = icmp eq i64 %index.next, %n.vec
  br i1 %16, label %middle.block, label %vector.body, !llvm.loop !9

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

scalar.ph.preheader:                              ; preds = %middle.block, %.preheader.us
  %indvars.iv.ph = phi i64 [ 0, %.preheader.us ], [ %n.vec, %middle.block ]
  %.115.us.ph = phi ptr [ %.01317.us, %.preheader.us ], [ %ind.end, %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
  %indvars.iv.prol = phi i64 [ %indvars.iv.next.prol, %scalar.ph.prol ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %.115.us.prol = phi ptr [ %17, %scalar.ph.prol ], [ %.115.us.ph, %scalar.ph.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %scalar.ph.prol ], [ 0, %scalar.ph.preheader ]
  %17 = getelementptr inbounds i8, ptr %.115.us.prol, i64 4
  %18 = load float, ptr %.115.us.prol, align 4, !tbaa !5
  %19 = mul nuw nsw i64 %indvars.iv.prol, %8
  %20 = getelementptr inbounds float, ptr %.01218.us, i64 %19
  store float %18, ptr %20, align 4, !tbaa !5
  %indvars.iv.next.prol = add nuw nsw i64 %indvars.iv.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 !13

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol, %scalar.ph.preheader
  %.lcssa31.unr = phi ptr [ poison, %scalar.ph.preheader ], [ %17, %scalar.ph.prol ]
  %indvars.iv.unr = phi i64 [ %indvars.iv.ph, %scalar.ph.preheader ], [ %indvars.iv.next.prol, %scalar.ph.prol ]
  %.115.us.unr = phi ptr [ %.115.us.ph, %scalar.ph.preheader ], [ %17, %scalar.ph.prol ]
  %21 = sub nsw i64 %indvars.iv.ph, %wide.trip.count
  %22 = icmp ugt i64 %21, -4
  br i1 %22, label %._crit_edge.us, label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next.3, %scalar.ph ], [ %indvars.iv.unr, %scalar.ph.prol.loopexit ]
  %.115.us = phi ptr [ %35, %scalar.ph ], [ %.115.us.unr, %scalar.ph.prol.loopexit ]
  %23 = getelementptr inbounds i8, ptr %.115.us, i64 4
  %24 = load float, ptr %.115.us, align 4, !tbaa !5
  %25 = mul nuw nsw i64 %indvars.iv, %8
  %26 = getelementptr inbounds float, ptr %.01218.us, i64 %25
  store float %24, ptr %26, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %27 = getelementptr inbounds i8, ptr %.115.us, i64 8
  %28 = load float, ptr %23, align 4, !tbaa !5
  %29 = mul nuw nsw i64 %indvars.iv.next, %8
  %30 = getelementptr inbounds float, ptr %.01218.us, i64 %29
  store float %28, ptr %30, align 4, !tbaa !5
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %31 = getelementptr inbounds i8, ptr %.115.us, i64 12
  %32 = load float, ptr %27, align 4, !tbaa !5
  %33 = mul nuw nsw i64 %indvars.iv.next.1, %8
  %34 = getelementptr inbounds float, ptr %.01218.us, i64 %33
  store float %32, ptr %34, align 4, !tbaa !5
  %indvars.iv.next.2 = add nuw nsw i64 %indvars.iv, 3
  %35 = getelementptr inbounds i8, ptr %.115.us, i64 16
  %36 = load float, ptr %31, align 4, !tbaa !5
  %37 = mul nuw nsw i64 %indvars.iv.next.2, %8
  %38 = getelementptr inbounds float, ptr %.01218.us, i64 %37
  store float %36, ptr %38, align 4, !tbaa !5
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %exitcond.not.3 = icmp eq i64 %indvars.iv.next.3, %wide.trip.count
  br i1 %exitcond.not.3, label %._crit_edge.us, label %scalar.ph, !llvm.loop !15

._crit_edge.us:                                   ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block
  %.lcssa = phi ptr [ %ind.end, %middle.block ], [ %.lcssa31.unr, %scalar.ph.prol.loopexit ], [ %35, %scalar.ph ]
  %39 = getelementptr inbounds i8, ptr %.01218.us, i64 4
  %40 = add nuw nsw i32 %.01119.us, 1
  %exitcond23.not = icmp eq i32 %40, %1
  %indvar.next = add i64 %indvar, 1
  br i1 %exitcond23.not, label %._crit_edge20, label %.preheader.us, !llvm.loop !16

._crit_edge20:                                    ; preds = %._crit_edge.us, %4
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.unroll.disable"}
!15 = distinct !{!15, !10, !11}
!16 = distinct !{!16, !10}


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