; LLVM IR from Thre4dripper/DSA-Programs :: 02. Matrix/11_Rotation.ll (Z17RotationClockwisePA5_ii)

; 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 @_Z17RotationClockwisePA5_ii(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca [5 x [5 x i32]], align 16
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 100, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %11

11:                                               ; preds = %44, %2
  %12 = load i32, ptr %6, align 4, !tbaa !9
  %13 = load i32, ptr %4, align 4, !tbaa !9
  %14 = icmp slt i32 %12, %13
  br i1 %14, label %16, label %15

15:                                               ; preds = %11
  store i32 2, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %47

16:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %17

17:                                               ; preds = %40, %16
  %18 = load i32, ptr %8, align 4, !tbaa !9
  %19 = load i32, ptr %4, align 4, !tbaa !9
  %20 = icmp slt i32 %18, %19
  br i1 %20, label %22, label %21

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

22:                                               ; preds = %17
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = load i32, ptr %4, align 4, !tbaa !9
  %25 = sub nsw i32 %24, 1
  %26 = load i32, ptr %8, align 4, !tbaa !9
  %27 = sub nsw i32 %25, %26
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [5 x i32], ptr %23, i64 %28
  %30 = load i32, ptr %6, align 4, !tbaa !9
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [5 x i32], ptr %29, i64 0, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !9
  %34 = load i32, ptr %6, align 4, !tbaa !9
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [5 x [5 x i32]], ptr %5, i64 0, i64 %35
  %37 = load i32, ptr %8, align 4, !tbaa !9
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [5 x i32], ptr %36, i64 0, i64 %38
  store i32 %33, ptr %39, align 4, !tbaa !9
  br label %40

40:                                               ; preds = %22
  %41 = load i32, ptr %8, align 4, !tbaa !9
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr %8, align 4, !tbaa !9
  br label %17, !llvm.loop !11

43:                                               ; preds = %21
  br label %44

44:                                               ; preds = %43
  %45 = load i32, ptr %6, align 4, !tbaa !9
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %6, align 4, !tbaa !9
  br label %11, !llvm.loop !13

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

48:                                               ; preds = %78, %47
  %49 = load i32, ptr %9, align 4, !tbaa !9
  %50 = load i32, ptr %4, align 4, !tbaa !9
  %51 = icmp slt i32 %49, %50
  br i1 %51, label %53, label %52

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

53:                                               ; preds = %48
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %54

54:                                               ; preds = %74, %53
  %55 = load i32, ptr %10, align 4, !tbaa !9
  %56 = load i32, ptr %4, align 4, !tbaa !9
  %57 = icmp slt i32 %55, %56
  br i1 %57, label %59, label %58

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

59:                                               ; preds = %54
  %60 = load i32, ptr %9, align 4, !tbaa !9
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [5 x [5 x i32]], ptr %5, i64 0, i64 %61
  %63 = load i32, ptr %10, align 4, !tbaa !9
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [5 x i32], ptr %62, i64 0, i64 %64
  %66 = load i32, ptr %65, align 4, !tbaa !9
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  %68 = load i32, ptr %9, align 4, !tbaa !9
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [5 x i32], ptr %67, i64 %69
  %71 = load i32, ptr %10, align 4, !tbaa !9
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [5 x i32], ptr %70, i64 0, i64 %72
  store i32 %66, ptr %73, align 4, !tbaa !9
  br label %74

74:                                               ; preds = %59
  %75 = load i32, ptr %10, align 4, !tbaa !9
  %76 = add nsw i32 %75, 1
  store i32 %76, ptr %10, align 4, !tbaa !9
  br label %54, !llvm.loop !14

77:                                               ; preds = %58
  br label %78

78:                                               ; preds = %77
  %79 = load i32, ptr %9, align 4, !tbaa !9
  %80 = add nsw i32 %79, 1
  store i32 %80, ptr %9, align 4, !tbaa !9
  br label %48, !llvm.loop !15

81:                                               ; preds = %52
  call void @llvm.lifetime.end.p0(i64 100, ptr %5) #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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}
!15 = distinct !{!15, !12}


; 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(argmem: readwrite) uwtable
define dso_local void @_Z17RotationClockwisePA5_ii(ptr nocapture noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = alloca [5 x [5 x i32]], align 16
  call void @llvm.lifetime.start.p0(i64 100, ptr nonnull %3) #3
  %4 = icmp sgt i32 %1, 0
  br i1 %4, label %.preheader27.us.preheader, label %._crit_edge32

.preheader27.us.preheader:                        ; preds = %2
  %5 = zext nneg i32 %1 to i64
  %wide.trip.count38 = zext nneg i32 %1 to i64
  %xtraiter = and i64 %wide.trip.count38, 1
  %6 = icmp eq i32 %1, 1
  %unroll_iter = and i64 %wide.trip.count38, 2147483646
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader27.us

.preheader27.us:                                  ; preds = %.preheader27.us.preheader, %._crit_edge.us
  %indvars.iv35 = phi i64 [ 0, %.preheader27.us.preheader ], [ %indvars.iv.next36, %._crit_edge.us ]
  br i1 %6, label %._crit_edge.us.unr-lcssa, label %.preheader27.us.new

.preheader27.us.new:                              ; preds = %.preheader27.us, %.preheader27.us.new
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %.preheader27.us.new ], [ 0, %.preheader27.us ]
  %niter = phi i64 [ %niter.next.1, %.preheader27.us.new ], [ 0, %.preheader27.us ]
  %7 = xor i64 %indvars.iv, -1
  %8 = add nsw i64 %7, %5
  %9 = getelementptr inbounds [5 x i32], ptr %0, i64 %8, i64 %indvars.iv35
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = getelementptr inbounds [5 x [5 x i32]], ptr %3, i64 0, i64 %indvars.iv35, i64 %indvars.iv
  store i32 %10, ptr %11, align 4, !tbaa !5
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %12 = xor i64 %indvars.iv, -2
  %13 = add nsw i64 %12, %5
  %14 = getelementptr inbounds [5 x i32], ptr %0, i64 %13, i64 %indvars.iv35
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = getelementptr inbounds [5 x [5 x i32]], ptr %3, i64 0, i64 %indvars.iv35, i64 %indvars.iv.next
  store i32 %15, ptr %16, align 4, !tbaa !5
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 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 %.preheader27.us.new, !llvm.loop !9

._crit_edge.us.unr-lcssa:                         ; preds = %.preheader27.us.new, %.preheader27.us
  %indvars.iv.unr = phi i64 [ 0, %.preheader27.us ], [ %indvars.iv.next.1, %.preheader27.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
  %17 = xor i64 %indvars.iv.unr, -1
  %18 = add nsw i64 %17, %5
  %19 = getelementptr inbounds [5 x i32], ptr %0, i64 %18, i64 %indvars.iv35
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = getelementptr inbounds [5 x [5 x i32]], ptr %3, i64 0, i64 %indvars.iv35, i64 %indvars.iv.unr
  store i32 %20, ptr %21, align 4, !tbaa !5
  br label %._crit_edge.us

._crit_edge.us:                                   ; preds = %._crit_edge.us.unr-lcssa, %._crit_edge.us.epilog-lcssa
  %indvars.iv.next36 = add nuw nsw i64 %indvars.iv35, 1
  %exitcond39.not = icmp eq i64 %indvars.iv.next36, %wide.trip.count38
  br i1 %exitcond39.not, label %.preheader26, label %.preheader27.us, !llvm.loop !11

.preheader26:                                     ; preds = %._crit_edge.us
  br i1 %4, label %.preheader.us.preheader, label %._crit_edge32

.preheader.us.preheader:                          ; preds = %.preheader26
  %22 = zext nneg i32 %1 to i64
  %23 = shl nuw nsw i64 %22, 2
  %xtraiter47 = and i64 %wide.trip.count38, 3
  %24 = icmp ult i32 %1, 4
  br i1 %24, label %._crit_edge32.loopexit.unr-lcssa, label %.preheader.us.preheader.new

.preheader.us.preheader.new:                      ; preds = %.preheader.us.preheader
  %unroll_iter49 = and i64 %wide.trip.count38, 2147483644
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us, %.preheader.us.preheader.new
  %indvar = phi i64 [ 0, %.preheader.us.preheader.new ], [ %indvar.next.3, %.preheader.us ]
  %niter50 = phi i64 [ 0, %.preheader.us.preheader.new ], [ %niter50.next.3, %.preheader.us ]
  %25 = mul nuw nsw i64 %indvar, 20
  %scevgep = getelementptr i8, ptr %0, i64 %25
  %scevgep40 = getelementptr i8, ptr %3, i64 %25
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %scevgep, ptr align 16 %scevgep40, i64 %23, i1 false), !tbaa !5
  %26 = mul nuw i64 %indvar, 20
  %27 = add nuw i64 %26, 20
  %scevgep.1 = getelementptr i8, ptr %0, i64 %27
  %scevgep40.1 = getelementptr i8, ptr %3, i64 %27
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %scevgep.1, ptr align 4 %scevgep40.1, i64 %23, i1 false), !tbaa !5
  %28 = mul nuw i64 %indvar, 20
  %29 = add nuw i64 %28, 40
  %scevgep.2 = getelementptr i8, ptr %0, i64 %29
  %scevgep40.2 = getelementptr i8, ptr %3, i64 %29
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %scevgep.2, ptr align 8 %scevgep40.2, i64 %23, i1 false), !tbaa !5
  %30 = mul nuw i64 %indvar, 20
  %31 = add nuw i64 %30, 60
  %scevgep.3 = getelementptr i8, ptr %0, i64 %31
  %scevgep40.3 = getelementptr i8, ptr %3, i64 %31
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %scevgep.3, ptr align 4 %scevgep40.3, i64 %23, i1 false), !tbaa !5
  %indvar.next.3 = add nuw nsw i64 %indvar, 4
  %niter50.next.3 = add i64 %niter50, 4
  %niter50.ncmp.3 = icmp eq i64 %niter50.next.3, %unroll_iter49
  br i1 %niter50.ncmp.3, label %._crit_edge32.loopexit.unr-lcssa, label %.preheader.us, !llvm.loop !12

._crit_edge32.loopexit.unr-lcssa:                 ; preds = %.preheader.us, %.preheader.us.preheader
  %indvar.unr = phi i64 [ 0, %.preheader.us.preheader ], [ %indvar.next.3, %.preheader.us ]
  %lcmp.mod48.not = icmp eq i64 %xtraiter47, 0
  br i1 %lcmp.mod48.not, label %._crit_edge32, label %.preheader.us.epil

.preheader.us.epil:                               ; preds = %._crit_edge32.loopexit.unr-lcssa, %.preheader.us.epil
  %indvar.epil = phi i64 [ %indvar.next.epil, %.preheader.us.epil ], [ %indvar.unr, %._crit_edge32.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.preheader.us.epil ], [ 0, %._crit_edge32.loopexit.unr-lcssa ]
  %32 = mul nuw nsw i64 %indvar.epil, 20
  %scevgep.epil = getelementptr i8, ptr %0, i64 %32
  %scevgep40.epil = getelementptr i8, ptr %3, i64 %32
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %scevgep.epil, ptr align 4 %scevgep40.epil, i64 %23, i1 false), !tbaa !5
  %indvar.next.epil = add nuw nsw i64 %indvar.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter47
  br i1 %epil.iter.cmp.not, label %._crit_edge32, label %.preheader.us.epil, !llvm.loop !13

._crit_edge32:                                    ; preds = %._crit_edge32.loopexit.unr-lcssa, %.preheader.us.epil, %2, %.preheader26
  call void @llvm.lifetime.end.p0(i64 100, ptr nonnull %3) #3
  ret void
}

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

attributes #0 = { mustprogress 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" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.unroll.disable"}


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