; LLVM IR from smv1999/CompetitiveProgrammingQuestionBank :: Sorting Algorithms/radix_sort.ll (Z12countingSortPiii)

; 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 @_Z12countingSortPiii(ptr noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca [10 x i32], align 16
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 40, ptr %7) #3
  %15 = load i32, ptr %5, align 4, !tbaa !9
  %16 = zext i32 %15 to i64
  %17 = call ptr @llvm.stacksave.p0()
  store ptr %17, ptr %8, align 8
  %18 = alloca i32, i64 %16, align 16
  store i64 %16, ptr %9, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %27, %3
  %20 = load i32, ptr %10, align 4, !tbaa !9
  %21 = icmp slt i32 %20, 10
  br i1 %21, label %23, label %22

22:                                               ; preds = %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %30

23:                                               ; preds = %19
  %24 = load i32, ptr %10, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [10 x i32], ptr %7, i64 0, i64 %25
  store i32 0, ptr %26, align 4, !tbaa !9
  br label %27

27:                                               ; preds = %23
  %28 = load i32, ptr %10, align 4, !tbaa !9
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %10, align 4, !tbaa !9
  br label %19, !llvm.loop !11

30:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %31

31:                                               ; preds = %49, %30
  %32 = load i32, ptr %11, align 4, !tbaa !9
  %33 = load i32, ptr %5, align 4, !tbaa !9
  %34 = icmp slt i32 %32, %33
  br i1 %34, label %36, label %35

35:                                               ; preds = %31
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %52

36:                                               ; preds = %31
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = load i32, ptr %11, align 4, !tbaa !9
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds i32, ptr %37, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !9
  %42 = load i32, ptr %6, align 4, !tbaa !9
  %43 = sdiv i32 %41, %42
  %44 = srem i32 %43, 10
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [10 x i32], ptr %7, i64 0, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !9
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %46, align 4, !tbaa !9
  br label %49

49:                                               ; preds = %36
  %50 = load i32, ptr %11, align 4, !tbaa !9
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %11, align 4, !tbaa !9
  br label %31, !llvm.loop !13

52:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  store i32 1, ptr %12, align 4, !tbaa !9
  br label %53

53:                                               ; preds = %72, %52
  %54 = load i32, ptr %12, align 4, !tbaa !9
  %55 = load i32, ptr %5, align 4, !tbaa !9
  %56 = icmp slt i32 %54, %55
  br i1 %56, label %58, label %57

57:                                               ; preds = %53
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %75

58:                                               ; preds = %53
  %59 = load i32, ptr %12, align 4, !tbaa !9
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [10 x i32], ptr %7, i64 0, i64 %60
  %62 = load i32, ptr %61, align 4, !tbaa !9
  %63 = load i32, ptr %12, align 4, !tbaa !9
  %64 = sub nsw i32 %63, 1
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [10 x i32], ptr %7, i64 0, i64 %65
  %67 = load i32, ptr %66, align 4, !tbaa !9
  %68 = add nsw i32 %62, %67
  %69 = load i32, ptr %12, align 4, !tbaa !9
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [10 x i32], ptr %7, i64 0, i64 %70
  store i32 %68, ptr %71, align 4, !tbaa !9
  br label %72

72:                                               ; preds = %58
  %73 = load i32, ptr %12, align 4, !tbaa !9
  %74 = add nsw i32 %73, 1
  store i32 %74, ptr %12, align 4, !tbaa !9
  br label %53, !llvm.loop !14

75:                                               ; preds = %57
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %76 = load i32, ptr %5, align 4, !tbaa !9
  %77 = sub nsw i32 %76, 1
  store i32 %77, ptr %13, align 4, !tbaa !9
  br label %78

78:                                               ; preds = %102, %75
  %79 = load i32, ptr %13, align 4, !tbaa !9
  %80 = icmp sge i32 %79, 0
  br i1 %80, label %82, label %81

81:                                               ; preds = %78
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  br label %105

82:                                               ; preds = %78
  %83 = load ptr, ptr %4, align 8, !tbaa !5
  %84 = load i32, ptr %13, align 4, !tbaa !9
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds i32, ptr %83, i64 %85
  %87 = load i32, ptr %86, align 4, !tbaa !9
  %88 = load ptr, ptr %4, align 8, !tbaa !5
  %89 = load i32, ptr %13, align 4, !tbaa !9
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds i32, ptr %88, i64 %90
  %92 = load i32, ptr %91, align 4, !tbaa !9
  %93 = load i32, ptr %6, align 4, !tbaa !9
  %94 = sdiv i32 %92, %93
  %95 = srem i32 %94, 10
  %96 = sext i32 %95 to i64
  %97 = getelementptr inbounds [10 x i32], ptr %7, i64 0, i64 %96
  %98 = load i32, ptr %97, align 4, !tbaa !9
  %99 = add nsw i32 %98, -1
  store i32 %99, ptr %97, align 4, !tbaa !9
  %100 = sext i32 %99 to i64
  %101 = getelementptr inbounds i32, ptr %18, i64 %100
  store i32 %87, ptr %101, align 4, !tbaa !9
  br label %102

102:                                              ; preds = %82
  %103 = load i32, ptr %13, align 4, !tbaa !9
  %104 = add nsw i32 %103, -1
  store i32 %104, ptr %13, align 4, !tbaa !9
  br label %78, !llvm.loop !15

105:                                              ; preds = %81
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  store i32 0, ptr %14, align 4, !tbaa !9
  br label %106

106:                                              ; preds = %120, %105
  %107 = load i32, ptr %14, align 4, !tbaa !9
  %108 = load i32, ptr %5, align 4, !tbaa !9
  %109 = icmp slt i32 %107, %108
  br i1 %109, label %111, label %110

110:                                              ; preds = %106
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  br label %123

111:                                              ; preds = %106
  %112 = load i32, ptr %14, align 4, !tbaa !9
  %113 = sext i32 %112 to i64
  %114 = getelementptr inbounds i32, ptr %18, i64 %113
  %115 = load i32, ptr %114, align 4, !tbaa !9
  %116 = load ptr, ptr %4, align 8, !tbaa !5
  %117 = load i32, ptr %14, align 4, !tbaa !9
  %118 = sext i32 %117 to i64
  %119 = getelementptr inbounds i32, ptr %116, i64 %118
  store i32 %115, ptr %119, align 4, !tbaa !9
  br label %120

120:                                              ; preds = %111
  %121 = load i32, ptr %14, align 4, !tbaa !9
  %122 = add nsw i32 %121, 1
  store i32 %122, ptr %14, align 4, !tbaa !9
  br label %106, !llvm.loop !16

123:                                              ; preds = %110
  %124 = load ptr, ptr %8, align 8
  call void @llvm.stackrestore.p0(ptr %124)
  call void @llvm.lifetime.end.p0(i64 40, ptr %7) #3
  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
declare ptr @llvm.stacksave.p0() #2

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

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #2

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 = { nocallback nofree nosync nounwind willreturn }
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 = !{!"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}
!16 = distinct !{!16, !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 uwtable
define dso_local void @_Z12countingSortPiii(ptr nocapture noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
.preheader37:
  %3 = alloca [10 x i32], align 16
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %3) #5
  %4 = zext i32 %1 to i64
  %5 = tail call ptr @llvm.stacksave.p0()
  %6 = alloca i32, i64 %4, align 16
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(40) %3, i8 0, i64 40, i1 false), !tbaa !5
  %7 = icmp sgt i32 %1, 0
  br i1 %7, label %.lr.ph, label %._crit_edge

.preheader36:                                     ; preds = %.lr.ph
  %.not = icmp eq i32 %1, 1
  br i1 %.not, label %.preheader35, label %.lr.ph41.preheader

.lr.ph41.preheader:                               ; preds = %.preheader36
  %.pre = load i32, ptr %3, align 16, !tbaa !5
  %8 = add nsw i64 %4, -1
  %9 = add nsw i64 %4, -2
  %xtraiter = and i64 %8, 3
  %10 = icmp ult i64 %9, 3
  br i1 %10, label %.preheader35.loopexit.unr-lcssa, label %.lr.ph41.preheader.new

.lr.ph41.preheader.new:                           ; preds = %.lr.ph41.preheader
  %unroll_iter = and i64 %8, -4
  br label %.lr.ph41

.lr.ph:                                           ; preds = %.preheader37, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.preheader37 ]
  %11 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = sdiv i32 %12, %2
  %14 = srem i32 %13, 10
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [10 x i32], ptr %3, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = add nsw i32 %17, 1
  store i32 %18, ptr %16, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %4
  br i1 %exitcond.not, label %.preheader36, label %.lr.ph, !llvm.loop !9

.preheader35.loopexit.unr-lcssa:                  ; preds = %.lr.ph41, %.lr.ph41.preheader
  %.unr = phi i32 [ %.pre, %.lr.ph41.preheader ], [ %35, %.lr.ph41 ]
  %indvars.iv48.unr = phi i64 [ 1, %.lr.ph41.preheader ], [ %indvars.iv.next49.3, %.lr.ph41 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.preheader35, label %.lr.ph41.epil

.lr.ph41.epil:                                    ; preds = %.preheader35.loopexit.unr-lcssa, %.lr.ph41.epil
  %19 = phi i32 [ %22, %.lr.ph41.epil ], [ %.unr, %.preheader35.loopexit.unr-lcssa ]
  %indvars.iv48.epil = phi i64 [ %indvars.iv.next49.epil, %.lr.ph41.epil ], [ %indvars.iv48.unr, %.preheader35.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph41.epil ], [ 0, %.preheader35.loopexit.unr-lcssa ]
  %20 = getelementptr inbounds [10 x i32], ptr %3, i64 0, i64 %indvars.iv48.epil
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = add nsw i32 %19, %21
  store i32 %22, ptr %20, align 4, !tbaa !5
  %indvars.iv.next49.epil = add nuw nsw i64 %indvars.iv48.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 %.preheader35, label %.lr.ph41.epil, !llvm.loop !11

.preheader35:                                     ; preds = %.preheader35.loopexit.unr-lcssa, %.lr.ph41.epil, %.preheader36
  br i1 %7, label %.lr.ph43, label %._crit_edge

.lr.ph41:                                         ; preds = %.lr.ph41, %.lr.ph41.preheader.new
  %23 = phi i32 [ %.pre, %.lr.ph41.preheader.new ], [ %35, %.lr.ph41 ]
  %indvars.iv48 = phi i64 [ 1, %.lr.ph41.preheader.new ], [ %indvars.iv.next49.3, %.lr.ph41 ]
  %niter = phi i64 [ 0, %.lr.ph41.preheader.new ], [ %niter.next.3, %.lr.ph41 ]
  %24 = getelementptr inbounds [10 x i32], ptr %3, i64 0, i64 %indvars.iv48
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = add nsw i32 %23, %25
  store i32 %26, ptr %24, align 4, !tbaa !5
  %indvars.iv.next49 = add nuw nsw i64 %indvars.iv48, 1
  %27 = getelementptr inbounds [10 x i32], ptr %3, i64 0, i64 %indvars.iv.next49
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = add nsw i32 %26, %28
  store i32 %29, ptr %27, align 4, !tbaa !5
  %indvars.iv.next49.1 = add nuw nsw i64 %indvars.iv48, 2
  %30 = getelementptr inbounds [10 x i32], ptr %3, i64 0, i64 %indvars.iv.next49.1
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = add nsw i32 %29, %31
  store i32 %32, ptr %30, align 4, !tbaa !5
  %indvars.iv.next49.2 = add nuw nsw i64 %indvars.iv48, 3
  %33 = getelementptr inbounds [10 x i32], ptr %3, i64 0, i64 %indvars.iv.next49.2
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = add nsw i32 %32, %34
  store i32 %35, ptr %33, align 4, !tbaa !5
  %indvars.iv.next49.3 = add nuw nsw i64 %indvars.iv48, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %.preheader35.loopexit.unr-lcssa, label %.lr.ph41, !llvm.loop !13

.preheader:                                       ; preds = %.lr.ph43
  br i1 %7, label %.lr.ph45.preheader, label %._crit_edge

.lr.ph45.preheader:                               ; preds = %.preheader
  %36 = shl nuw nsw i64 %4, 2
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 4 %0, ptr nonnull align 16 %6, i64 %36, i1 false), !tbaa !5
  br label %._crit_edge

.lr.ph43:                                         ; preds = %.preheader35, %.lr.ph43
  %indvars.iv53 = phi i64 [ %indvars.iv.next54, %.lr.ph43 ], [ %4, %.preheader35 ]
  %indvars.iv.next54 = add nsw i64 %indvars.iv53, -1
  %37 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv.next54
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = sdiv i32 %38, %2
  %40 = srem i32 %39, 10
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [10 x i32], ptr %3, i64 0, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = add nsw i32 %43, -1
  store i32 %44, ptr %42, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds i32, ptr %6, i64 %45
  store i32 %38, ptr %46, align 4, !tbaa !5
  %47 = icmp sgt i64 %indvars.iv53, 1
  br i1 %47, label %.lr.ph43, label %.preheader, !llvm.loop !14

._crit_edge:                                      ; preds = %.preheader37, %.preheader35, %.lr.ph45.preheader, %.preheader
  tail call void @llvm.stackrestore.p0(ptr %5)
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %3) #5
  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
declare ptr @llvm.stacksave.p0() #2

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; 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) #4

attributes #0 = { mustprogress nofree norecurse nosync 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nosync nounwind willreturn }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { 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, !12}
!12 = !{!"llvm.loop.unroll.disable"}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass