; LLVM IR from Thre4dripper/DSA-Programs :: 17. Sorting Algorithms/RadixSort.ll (Z9RadixSortPii)

; 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 uwtable
declare dso_local void @_Z12InsertBucketiiPP4Node(i32 noundef, i32 noundef, ptr noundef) #0

; 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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z12RemoveBucketiPP4Node(i32 noundef, ptr noundef) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z9MaxDigitsPii(ptr noundef, i32 noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_Z9RadixSortPii(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca [10 x ptr], align 16
  %9 = alloca i32, align 4
  %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
  %15 = alloca i32, align 4
  %16 = 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 4, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 80, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %17

17:                                               ; preds = %25, %2
  %18 = load i32, ptr %9, align 4, !tbaa !9
  %19 = icmp slt i32 %18, 10
  br i1 %19, label %21, label %20

20:                                               ; preds = %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  br label %28

21:                                               ; preds = %17
  %22 = load i32, ptr %9, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [10 x ptr], ptr %8, i64 0, i64 %23
  store ptr null, ptr %24, align 8, !tbaa !5
  br label %25

25:                                               ; preds = %21
  %26 = load i32, ptr %9, align 4, !tbaa !9
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr %9, align 4, !tbaa !9
  br label %17, !llvm.loop !11

28:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = load i32, ptr %4, align 4, !tbaa !9
  %31 = call noundef i32 @_Z9MaxDigitsPii(ptr noundef %29, i32 noundef %30)
  store i32 %31, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  store i32 0, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  store i32 0, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  store i32 1, ptr %13, align 4, !tbaa !9
  br label %32

32:                                               ; preds = %93, %28
  %33 = load i32, ptr %13, align 4, !tbaa !9
  %34 = load i32, ptr %10, align 4, !tbaa !9
  %35 = icmp sle i32 %33, %34
  br i1 %35, label %37, label %36

36:                                               ; preds = %32
  store i32 5, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  br label %96

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

38:                                               ; preds = %65, %37
  %39 = load i32, ptr %15, align 4, !tbaa !9
  %40 = load i32, ptr %4, align 4, !tbaa !9
  %41 = icmp slt i32 %39, %40
  br i1 %41, label %43, label %42

42:                                               ; preds = %38
  store i32 8, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  br label %68

43:                                               ; preds = %38
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = load i32, ptr %15, align 4, !tbaa !9
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds i32, ptr %44, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !9
  %49 = load i32, ptr %13, align 4, !tbaa !9
  %50 = call noundef double @_ZSt3powIiiEN9__gnu_cxx9__promoteIDTplcvNS1_IT_Xsr3std12__is_integerIS2_EE7__valueEE6__typeELi0EcvNS1_IT0_Xsr3std12__is_integerIS5_EE7__valueEE6__typeELi0EEXsr3std12__is_integerIS8_EE7__valueEE6__typeES2_S5_(i32 noundef 10, i32 noundef %49)
  %51 = fptosi double %50 to i32
  %52 = srem i32 %48, %51
  %53 = load i32, ptr %13, align 4, !tbaa !9
  %54 = sub nsw i32 %53, 1
  %55 = call noundef double @_ZSt3powIiiEN9__gnu_cxx9__promoteIDTplcvNS1_IT_Xsr3std12__is_integerIS2_EE7__valueEE6__typeELi0EcvNS1_IT0_Xsr3std12__is_integerIS5_EE7__valueEE6__typeELi0EEXsr3std12__is_integerIS8_EE7__valueEE6__typeES2_S5_(i32 noundef 10, i32 noundef %54)
  %56 = fptosi double %55 to i32
  %57 = sdiv i32 %52, %56
  store i32 %57, ptr %12, align 4, !tbaa !9
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = load i32, ptr %15, align 4, !tbaa !9
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds i32, ptr %58, i64 %60
  %62 = load i32, ptr %61, align 4, !tbaa !9
  %63 = load i32, ptr %12, align 4, !tbaa !9
  %64 = getelementptr inbounds [10 x ptr], ptr %8, i64 0, i64 0
  call void @_Z12InsertBucketiiPP4Node(i32 noundef %62, i32 noundef %63, ptr noundef %64)
  br label %65

65:                                               ; preds = %43
  %66 = load i32, ptr %15, align 4, !tbaa !9
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %15, align 4, !tbaa !9
  br label %38, !llvm.loop !13

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

69:                                               ; preds = %89, %68
  %70 = load i32, ptr %16, align 4, !tbaa !9
  %71 = icmp slt i32 %70, 10
  br i1 %71, label %73, label %72

72:                                               ; preds = %69
  store i32 11, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #4
  br label %92

73:                                               ; preds = %69
  %74 = load i32, ptr %16, align 4, !tbaa !9
  %75 = getelementptr inbounds [10 x ptr], ptr %8, i64 0, i64 0
  %76 = call noundef i32 @_Z12RemoveBucketiPP4Node(i32 noundef %74, ptr noundef %75)
  store i32 %76, ptr %11, align 4, !tbaa !9
  %77 = load i32, ptr %11, align 4, !tbaa !9
  %78 = icmp ne i32 %77, -1
  br i1 %78, label %79, label %88

79:                                               ; preds = %73
  %80 = load i32, ptr %11, align 4, !tbaa !9
  %81 = load ptr, ptr %3, align 8, !tbaa !5
  %82 = load i32, ptr %7, align 4, !tbaa !9
  %83 = add nsw i32 %82, 1
  store i32 %83, ptr %7, align 4, !tbaa !9
  %84 = sext i32 %82 to i64
  %85 = getelementptr inbounds i32, ptr %81, i64 %84
  store i32 %80, ptr %85, align 4, !tbaa !9
  %86 = load i32, ptr %16, align 4, !tbaa !9
  %87 = add nsw i32 %86, -1
  store i32 %87, ptr %16, align 4, !tbaa !9
  br label %88

88:                                               ; preds = %79, %73
  br label %89

89:                                               ; preds = %88
  %90 = load i32, ptr %16, align 4, !tbaa !9
  %91 = add nsw i32 %90, 1
  store i32 %91, ptr %16, align 4, !tbaa !9
  br label %69, !llvm.loop !14

92:                                               ; preds = %72
  br label %93

93:                                               ; preds = %92
  %94 = load i32, ptr %13, align 4, !tbaa !9
  %95 = add nsw i32 %94, 1
  store i32 %95, ptr %13, align 4, !tbaa !9
  br label %32, !llvm.loop !15

96:                                               ; preds = %36
  %97 = load ptr, ptr %3, align 8, !tbaa !5
  store i32 1, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 80, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret ptr %97
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt3powIiiEN9__gnu_cxx9__promoteIDTplcvNS1_IT_Xsr3std12__is_integerIS2_EE7__valueEE6__typeELi0EcvNS1_IT0_Xsr3std12__is_integerIS5_EE7__valueEE6__typeELi0EEXsr3std12__is_integerIS8_EE7__valueEE6__typeES2_S5_(i32 noundef, i32 noundef) #3

attributes #0 = { mustprogress 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 = { 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 #3 = { inlinehint 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 #4 = { 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 uwtable
declare dso_local void @_Z12InsertBucketiiPP4Node(i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; 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: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z12RemoveBucketiPP4Node(i32 noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z9MaxDigitsPii(ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_Z9RadixSortPii(ptr noundef returned %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = alloca [10 x ptr], align 16
  call void @llvm.lifetime.start.p0(i64 80, ptr nonnull %3) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(80) %3, i8 0, i64 80, i1 false), !tbaa !5
  %4 = tail call noundef i32 @_Z9MaxDigitsPii(ptr noundef %0, i32 noundef %1)
  %.not38 = icmp slt i32 %4, 1
  br i1 %.not38, label %._crit_edge, label %.preheader33.lr.ph

.preheader33.lr.ph:                               ; preds = %2
  %5 = icmp sgt i32 %1, 0
  br i1 %5, label %.preheader33.us.preheader, label %.preheader33

.preheader33.us.preheader:                        ; preds = %.preheader33.lr.ph
  %wide.trip.count = zext nneg i32 %1 to i64
  br label %.preheader33.us

.preheader33.us:                                  ; preds = %.preheader33.us.preheader, %7
  %.02739.us = phi i32 [ %8, %7 ], [ 1, %.preheader33.us.preheader ]
  %6 = add nsw i32 %.02739.us, -1
  br label %18

7:                                                ; preds = %15
  %8 = add nuw i32 %.02739.us, 1
  %exitcond44.not = icmp eq i32 %.02739.us, %4
  br i1 %exitcond44.not, label %._crit_edge, label %.preheader33.us, !llvm.loop !9

..preheader_crit_edge.us:                         ; preds = %18, %15
  %.037.us = phi i32 [ %16, %15 ], [ 0, %18 ]
  %.02836.us = phi i32 [ %.129.us, %15 ], [ 0, %18 ]
  %9 = call noundef i32 @_Z12RemoveBucketiPP4Node(i32 noundef %.037.us, ptr noundef nonnull %3)
  %.not32.us = icmp eq i32 %9, -1
  br i1 %.not32.us, label %15, label %10

10:                                               ; preds = %..preheader_crit_edge.us
  %11 = add nsw i32 %.02836.us, 1
  %12 = sext i32 %.02836.us to i64
  %13 = getelementptr inbounds i32, ptr %0, i64 %12
  store i32 %9, ptr %13, align 4, !tbaa !11
  %14 = add nsw i32 %.037.us, -1
  br label %15

15:                                               ; preds = %10, %..preheader_crit_edge.us
  %.129.us = phi i32 [ %11, %10 ], [ %.02836.us, %..preheader_crit_edge.us ]
  %.1.us = phi i32 [ %14, %10 ], [ %.037.us, %..preheader_crit_edge.us ]
  %16 = add nsw i32 %.1.us, 1
  %17 = icmp slt i32 %.1.us, 9
  br i1 %17, label %..preheader_crit_edge.us, label %7, !llvm.loop !13

18:                                               ; preds = %.preheader33.us, %18
  %indvars.iv = phi i64 [ 0, %.preheader33.us ], [ %indvars.iv.next, %18 ]
  %19 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv
  %20 = load i32, ptr %19, align 4, !tbaa !11
  %21 = call noundef double @_ZSt3powIiiEN9__gnu_cxx9__promoteIDTplcvNS1_IT_Xsr3std12__is_integerIS2_EE7__valueEE6__typeELi0EcvNS1_IT0_Xsr3std12__is_integerIS5_EE7__valueEE6__typeELi0EEXsr3std12__is_integerIS8_EE7__valueEE6__typeES2_S5_(i32 noundef 10, i32 noundef %.02739.us)
  %22 = fptosi double %21 to i32
  %23 = srem i32 %20, %22
  %24 = call noundef double @_ZSt3powIiiEN9__gnu_cxx9__promoteIDTplcvNS1_IT_Xsr3std12__is_integerIS2_EE7__valueEE6__typeELi0EcvNS1_IT0_Xsr3std12__is_integerIS5_EE7__valueEE6__typeELi0EEXsr3std12__is_integerIS8_EE7__valueEE6__typeES2_S5_(i32 noundef 10, i32 noundef %6)
  %25 = fptosi double %24 to i32
  %26 = sdiv i32 %23, %25
  %27 = load i32, ptr %19, align 4, !tbaa !11
  call void @_Z12InsertBucketiiPP4Node(i32 noundef %27, i32 noundef %26, ptr noundef nonnull %3)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond43.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond43.not, label %..preheader_crit_edge.us, label %18, !llvm.loop !14

.preheader33:                                     ; preds = %.preheader33.lr.ph, %28
  %.02739 = phi i32 [ %29, %28 ], [ 1, %.preheader33.lr.ph ]
  br label %30

._crit_edge:                                      ; preds = %28, %7, %2
  call void @llvm.lifetime.end.p0(i64 80, ptr nonnull %3) #5
  ret ptr %0

28:                                               ; preds = %37
  %29 = add nuw i32 %.02739, 1
  %exitcond.not = icmp eq i32 %.02739, %4
  br i1 %exitcond.not, label %._crit_edge, label %.preheader33, !llvm.loop !9

30:                                               ; preds = %.preheader33, %37
  %.037 = phi i32 [ 0, %.preheader33 ], [ %38, %37 ]
  %.02836 = phi i32 [ 0, %.preheader33 ], [ %.129, %37 ]
  %31 = call noundef i32 @_Z12RemoveBucketiPP4Node(i32 noundef %.037, ptr noundef nonnull %3)
  %.not32 = icmp eq i32 %31, -1
  br i1 %.not32, label %37, label %32

32:                                               ; preds = %30
  %33 = add nsw i32 %.02836, 1
  %34 = sext i32 %.02836 to i64
  %35 = getelementptr inbounds i32, ptr %0, i64 %34
  store i32 %31, ptr %35, align 4, !tbaa !11
  %36 = add nsw i32 %.037, -1
  br label %37

37:                                               ; preds = %30, %32
  %.129 = phi i32 [ %33, %32 ], [ %.02836, %30 ]
  %.1 = phi i32 [ %36, %32 ], [ %.037, %30 ]
  %38 = add nsw i32 %.1, 1
  %39 = icmp slt i32 %.1, 9
  br i1 %39, label %30, label %28, !llvm.loop !13
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt3powIiiEN9__gnu_cxx9__promoteIDTplcvNS1_IT_Xsr3std12__is_integerIS2_EE7__valueEE6__typeELi0EcvNS1_IT0_Xsr3std12__is_integerIS5_EE7__valueEE6__typeELi0EEXsr3std12__is_integerIS8_EE7__valueEE6__typeES2_S5_(i32 noundef, i32 noundef) local_unnamed_addr #3

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

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


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