; LLVM IR from h-ssiqueira/Sort_Algorithms :: src/noncomparisonDistribution (radixLSDSort)

; 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 @countingByDigit(ptr noundef %0, i32 noundef %1, i32 noundef %2, i64 noundef %3, i32 noundef %4) #0 {
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i64 %3, ptr %9, align 8, !tbaa !11
  store i32 %4, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #6
  %16 = load i32, ptr %7, align 4, !tbaa !9
  %17 = sext i32 %16 to i64
  %18 = call noalias ptr @calloc(i64 noundef %17, i64 noundef 8) #7
  store ptr %18, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #6
  %19 = load i32, ptr %10, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = mul i64 %20, 8
  %22 = call noalias ptr @malloc(i64 noundef %21) #8
  store ptr %22, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #6
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %23, ptr %14, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %51, %5
  %25 = load ptr, ptr %14, align 8, !tbaa !5
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = load i32, ptr %10, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds i64, ptr %26, i64 %28
  %30 = icmp ult ptr %25, %29
  br i1 %30, label %31, label %54

31:                                               ; preds = %24
  %32 = load ptr, ptr %14, align 8, !tbaa !5
  %33 = load i64, ptr %32, align 8, !tbaa !11
  %34 = load i64, ptr %9, align 8, !tbaa !11
  %35 = sub nsw i64 %33, %34
  %36 = load i32, ptr %8, align 4, !tbaa !9
  %37 = sext i32 %36 to i64
  %38 = sdiv i64 %35, %37
  %39 = load i32, ptr %7, align 4, !tbaa !9
  %40 = sext i32 %39 to i64
  %41 = srem i64 %38, %40
  %42 = sitofp i64 %41 to double
  %43 = call double @llvm.floor.f64(double %42)
  %44 = fptosi double %43 to i32
  store i32 %44, ptr %11, align 4, !tbaa !9
  %45 = load ptr, ptr %12, align 8, !tbaa !5
  %46 = load i32, ptr %11, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds i64, ptr %45, i64 %47
  %49 = load i64, ptr %48, align 8, !tbaa !11
  %50 = add nsw i64 %49, 1
  store i64 %50, ptr %48, align 8, !tbaa !11
  br label %51

51:                                               ; preds = %31
  %52 = load ptr, ptr %14, align 8, !tbaa !5
  %53 = getelementptr inbounds i64, ptr %52, i32 1
  store ptr %53, ptr %14, align 8, !tbaa !5
  br label %24, !llvm.loop !13

54:                                               ; preds = %24
  %55 = load ptr, ptr %12, align 8, !tbaa !5
  %56 = getelementptr inbounds i64, ptr %55, i64 1
  store ptr %56, ptr %14, align 8, !tbaa !5
  br label %57

57:                                               ; preds = %71, %54
  %58 = load ptr, ptr %14, align 8, !tbaa !5
  %59 = load ptr, ptr %12, align 8, !tbaa !5
  %60 = load i32, ptr %7, align 4, !tbaa !9
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds i64, ptr %59, i64 %61
  %63 = icmp ult ptr %58, %62
  br i1 %63, label %64, label %74

64:                                               ; preds = %57
  %65 = load ptr, ptr %14, align 8, !tbaa !5
  %66 = getelementptr inbounds i64, ptr %65, i64 -1
  %67 = load i64, ptr %66, align 8, !tbaa !11
  %68 = load ptr, ptr %14, align 8, !tbaa !5
  %69 = load i64, ptr %68, align 8, !tbaa !11
  %70 = add nsw i64 %69, %67
  store i64 %70, ptr %68, align 8, !tbaa !11
  br label %71

71:                                               ; preds = %64
  %72 = load ptr, ptr %14, align 8, !tbaa !5
  %73 = getelementptr inbounds i64, ptr %72, i32 1
  store ptr %73, ptr %14, align 8, !tbaa !5
  br label %57, !llvm.loop !15

74:                                               ; preds = %57
  %75 = load ptr, ptr %6, align 8, !tbaa !5
  %76 = load i32, ptr %10, align 4, !tbaa !9
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds i64, ptr %75, i64 %77
  %79 = getelementptr inbounds i64, ptr %78, i64 -1
  store ptr %79, ptr %14, align 8, !tbaa !5
  br label %80

80:                                               ; preds = %108, %74
  %81 = load ptr, ptr %14, align 8, !tbaa !5
  %82 = load ptr, ptr %6, align 8, !tbaa !5
  %83 = icmp uge ptr %81, %82
  br i1 %83, label %84, label %111

84:                                               ; preds = %80
  %85 = load ptr, ptr %14, align 8, !tbaa !5
  %86 = load i64, ptr %85, align 8, !tbaa !11
  %87 = load i64, ptr %9, align 8, !tbaa !11
  %88 = sub nsw i64 %86, %87
  %89 = load i32, ptr %8, align 4, !tbaa !9
  %90 = sext i32 %89 to i64
  %91 = sdiv i64 %88, %90
  %92 = load i32, ptr %7, align 4, !tbaa !9
  %93 = sext i32 %92 to i64
  %94 = srem i64 %91, %93
  %95 = sitofp i64 %94 to double
  %96 = call double @llvm.floor.f64(double %95)
  %97 = fptosi double %96 to i32
  store i32 %97, ptr %11, align 4, !tbaa !9
  %98 = load ptr, ptr %14, align 8, !tbaa !5
  %99 = load i64, ptr %98, align 8, !tbaa !11
  %100 = load ptr, ptr %13, align 8, !tbaa !5
  %101 = load ptr, ptr %12, align 8, !tbaa !5
  %102 = load i32, ptr %11, align 4, !tbaa !9
  %103 = sext i32 %102 to i64
  %104 = getelementptr inbounds i64, ptr %101, i64 %103
  %105 = load i64, ptr %104, align 8, !tbaa !11
  %106 = add nsw i64 %105, -1
  store i64 %106, ptr %104, align 8, !tbaa !11
  %107 = getelementptr inbounds i64, ptr %100, i64 %106
  store i64 %99, ptr %107, align 8, !tbaa !11
  br label %108

108:                                              ; preds = %84
  %109 = load ptr, ptr %14, align 8, !tbaa !5
  %110 = getelementptr inbounds i64, ptr %109, i32 -1
  store ptr %110, ptr %14, align 8, !tbaa !5
  br label %80, !llvm.loop !16

111:                                              ; preds = %80
  %112 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %112, ptr %14, align 8, !tbaa !5
  %113 = load ptr, ptr %13, align 8, !tbaa !5
  store ptr %113, ptr %15, align 8, !tbaa !5
  br label %114

114:                                              ; preds = %125, %111
  %115 = load ptr, ptr %14, align 8, !tbaa !5
  %116 = load ptr, ptr %6, align 8, !tbaa !5
  %117 = load i32, ptr %10, align 4, !tbaa !9
  %118 = sext i32 %117 to i64
  %119 = getelementptr inbounds i64, ptr %116, i64 %118
  %120 = icmp ult ptr %115, %119
  br i1 %120, label %121, label %130

121:                                              ; preds = %114
  %122 = load ptr, ptr %15, align 8, !tbaa !5
  %123 = load i64, ptr %122, align 8, !tbaa !11
  %124 = load ptr, ptr %14, align 8, !tbaa !5
  store i64 %123, ptr %124, align 8, !tbaa !11
  br label %125

125:                                              ; preds = %121
  %126 = load ptr, ptr %14, align 8, !tbaa !5
  %127 = getelementptr inbounds i64, ptr %126, i32 1
  store ptr %127, ptr %14, align 8, !tbaa !5
  %128 = load ptr, ptr %15, align 8, !tbaa !5
  %129 = getelementptr inbounds i64, ptr %128, i32 1
  store ptr %129, ptr %15, align 8, !tbaa !5
  br label %114, !llvm.loop !17

130:                                              ; preds = %114
  %131 = load ptr, ptr %12, align 8, !tbaa !5
  call void @free(ptr noundef %131) #6
  %132 = load ptr, ptr %13, align 8, !tbaa !5
  call void @free(ptr noundef %132) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #6
  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: nounwind allocsize(0,1)
declare noalias ptr @calloc(i64 noundef, i64 noundef) #2

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.floor.f64(double) #4

; Function Attrs: nounwind
declare void @free(ptr noundef) #5

; 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 allocsize(0,1) "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 = { nounwind allocsize(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 nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { nounwind "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 #6 = { nounwind }
attributes #7 = { nounwind allocsize(0,1) }
attributes #8 = { nounwind allocsize(0) }

!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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}
!17 = distinct !{!17, !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: nounwind uwtable
define dso_local void @countingByDigit(ptr noundef %0, i32 noundef %1, i32 noundef %2, i64 noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  %6 = ptrtoint ptr %0 to i64
  %7 = sext i32 %1 to i64
  %8 = tail call noalias ptr @calloc(i64 noundef %7, i64 noundef 8) #6
  %9 = sext i32 %4 to i64
  %10 = shl nsw i64 %9, 3
  %11 = tail call noalias ptr @malloc(i64 noundef %10) #7
  %12 = getelementptr inbounds i64, ptr %0, i64 %9
  %13 = icmp sgt i32 %4, 0
  br i1 %13, label %.lr.ph, label %.preheader49

.lr.ph:                                           ; preds = %5
  %14 = sext i32 %2 to i64
  br label %17

.preheader49:                                     ; preds = %17, %5
  %.idx = shl nsw i64 %7, 3
  %15 = getelementptr inbounds i8, ptr %8, i64 %.idx
  %16 = icmp sgt i32 %1, 1
  br i1 %16, label %.lr.ph54.preheader, label %.preheader48

.lr.ph54.preheader:                               ; preds = %.preheader49
  %.151 = getelementptr inbounds i8, ptr %8, i64 8
  %.pre = load i64, ptr %8, align 8, !tbaa !5
  br label %.lr.ph54

17:                                               ; preds = %.lr.ph, %17
  %.04350 = phi ptr [ %0, %.lr.ph ], [ %26, %17 ]
  %18 = load i64, ptr %.04350, align 8, !tbaa !5
  %19 = sub nsw i64 %18, %3
  %20 = sdiv i64 %19, %14
  %21 = srem i64 %20, %7
  %22 = shl nsw i64 %21, 3
  %23 = getelementptr inbounds i8, ptr %8, i64 %22
  %24 = load i64, ptr %23, align 8, !tbaa !5
  %25 = add nsw i64 %24, 1
  store i64 %25, ptr %23, align 8, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %.04350, i64 8
  %27 = icmp ult ptr %26, %12
  br i1 %27, label %17, label %.preheader49, !llvm.loop !9

.preheader48:                                     ; preds = %.lr.ph54, %.preheader49
  %.255 = getelementptr inbounds i8, ptr %12, i64 -8
  %.not56 = icmp ult ptr %.255, %0
  br i1 %.not56, label %.preheader, label %.lr.ph58

.lr.ph58:                                         ; preds = %.preheader48
  %28 = sext i32 %2 to i64
  br label %39

.lr.ph54:                                         ; preds = %.lr.ph54.preheader, %.lr.ph54
  %29 = phi i64 [ %31, %.lr.ph54 ], [ %.pre, %.lr.ph54.preheader ]
  %.153 = phi ptr [ %.1, %.lr.ph54 ], [ %.151, %.lr.ph54.preheader ]
  %30 = load i64, ptr %.153, align 8, !tbaa !5
  %31 = add nsw i64 %30, %29
  store i64 %31, ptr %.153, align 8, !tbaa !5
  %.1 = getelementptr inbounds i8, ptr %.153, i64 8
  %32 = icmp ult ptr %.1, %15
  br i1 %32, label %.lr.ph54, label %.preheader48, !llvm.loop !11

.preheader:                                       ; preds = %39, %.preheader48
  br i1 %13, label %.lr.ph61.preheader, label %._crit_edge

.lr.ph61.preheader:                               ; preds = %.preheader
  %33 = add i64 %10, %6
  %34 = add i64 %6, 8
  %umax = tail call i64 @llvm.umax.i64(i64 %33, i64 %34)
  %35 = xor i64 %6, -1
  %36 = add i64 %umax, %35
  %37 = and i64 %36, -8
  %38 = add i64 %37, 8
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 8 %0, ptr align 8 %11, i64 %38, i1 false), !tbaa !5
  br label %._crit_edge

39:                                               ; preds = %.lr.ph58, %39
  %.257 = phi ptr [ %.255, %.lr.ph58 ], [ %.2, %39 ]
  %40 = load i64, ptr %.257, align 8, !tbaa !5
  %41 = sub nsw i64 %40, %3
  %42 = sdiv i64 %41, %28
  %43 = srem i64 %42, %7
  %44 = shl nsw i64 %43, 3
  %45 = getelementptr inbounds i8, ptr %8, i64 %44
  %46 = load i64, ptr %45, align 8, !tbaa !5
  %47 = add nsw i64 %46, -1
  store i64 %47, ptr %45, align 8, !tbaa !5
  %48 = getelementptr inbounds i64, ptr %11, i64 %47
  store i64 %40, ptr %48, align 8, !tbaa !5
  %.2 = getelementptr inbounds i8, ptr %.257, i64 -8
  %.not = icmp ult ptr %.2, %0
  br i1 %.not, label %.preheader, label %39, !llvm.loop !12

._crit_edge:                                      ; preds = %.lr.ph61.preheader, %.preheader
  tail call void @free(ptr noundef %8) #8
  tail call void @free(ptr noundef %11) #8
  ret void
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umax.i64(i64, i64) #4

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

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 = { mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 #2 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #6 = { nounwind allocsize(0,1) }
attributes #7 = { nounwind allocsize(0) }
attributes #8 = { 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass