; LLVM IR from aryanmid123/c-sorting-algorithms :: test (radix_sort_test)

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

18:                                               ; preds = %108, %2
  %19 = load i32, ptr %9, align 4, !tbaa !9
  %20 = load i32, ptr %8, align 4, !tbaa !9
  %21 = sdiv i32 %19, %20
  %22 = icmp sgt i32 %21, 0
  br i1 %22, label %23, label %111

23:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 40, ptr %10) #4
  call void @llvm.memset.p0.i64(ptr align 16 %10, i8 0, i64 40, i1 false)
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %24

24:                                               ; preds = %41, %23
  %25 = load i32, ptr %5, align 4, !tbaa !9
  %26 = load i32, ptr %4, align 4, !tbaa !9
  %27 = icmp slt i32 %25, %26
  br i1 %27, label %28, label %44

28:                                               ; preds = %24
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = load i32, ptr %5, align 4, !tbaa !9
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds i32, ptr %29, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !9
  %34 = load i32, ptr %8, align 4, !tbaa !9
  %35 = sdiv i32 %33, %34
  %36 = srem i32 %35, 10
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [10 x i32], ptr %10, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !9
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %38, align 4, !tbaa !9
  br label %41

41:                                               ; preds = %28
  %42 = load i32, ptr %5, align 4, !tbaa !9
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %5, align 4, !tbaa !9
  br label %24, !llvm.loop !11

44:                                               ; preds = %24
  store i32 1, ptr %5, align 4, !tbaa !9
  br label %45

45:                                               ; preds = %59, %44
  %46 = load i32, ptr %5, align 4, !tbaa !9
  %47 = icmp slt i32 %46, 10
  br i1 %47, label %48, label %62

48:                                               ; preds = %45
  %49 = load i32, ptr %5, align 4, !tbaa !9
  %50 = sub nsw i32 %49, 1
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [10 x i32], ptr %10, i64 0, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !9
  %54 = load i32, ptr %5, align 4, !tbaa !9
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [10 x i32], ptr %10, i64 0, i64 %55
  %57 = load i32, ptr %56, align 4, !tbaa !9
  %58 = add nsw i32 %57, %53
  store i32 %58, ptr %56, align 4, !tbaa !9
  br label %59

59:                                               ; preds = %48
  %60 = load i32, ptr %5, align 4, !tbaa !9
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %5, align 4, !tbaa !9
  br label %45, !llvm.loop !13

62:                                               ; preds = %45
  %63 = load i32, ptr %4, align 4, !tbaa !9
  %64 = sub nsw i32 %63, 1
  store i32 %64, ptr %5, align 4, !tbaa !9
  br label %65

65:                                               ; preds = %88, %62
  %66 = load i32, ptr %5, align 4, !tbaa !9
  %67 = icmp sge i32 %66, 0
  br i1 %67, label %68, label %91

68:                                               ; preds = %65
  %69 = load ptr, ptr %3, align 8, !tbaa !5
  %70 = load i32, ptr %5, align 4, !tbaa !9
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds i32, ptr %69, i64 %71
  %73 = load i32, ptr %72, align 4, !tbaa !9
  %74 = load ptr, ptr %3, align 8, !tbaa !5
  %75 = load i32, ptr %5, align 4, !tbaa !9
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds i32, ptr %74, i64 %76
  %78 = load i32, ptr %77, align 4, !tbaa !9
  %79 = load i32, ptr %8, align 4, !tbaa !9
  %80 = sdiv i32 %78, %79
  %81 = srem i32 %80, 10
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds [10 x i32], ptr %10, i64 0, i64 %82
  %84 = load i32, ptr %83, align 4, !tbaa !9
  %85 = add nsw i32 %84, -1
  store i32 %85, ptr %83, align 4, !tbaa !9
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds i32, ptr %14, i64 %86
  store i32 %73, ptr %87, align 4, !tbaa !9
  br label %88

88:                                               ; preds = %68
  %89 = load i32, ptr %5, align 4, !tbaa !9
  %90 = add nsw i32 %89, -1
  store i32 %90, ptr %5, align 4, !tbaa !9
  br label %65, !llvm.loop !14

91:                                               ; preds = %65
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %92

92:                                               ; preds = %105, %91
  %93 = load i32, ptr %5, align 4, !tbaa !9
  %94 = load i32, ptr %4, align 4, !tbaa !9
  %95 = icmp slt i32 %93, %94
  br i1 %95, label %96, label %108

96:                                               ; preds = %92
  %97 = load i32, ptr %5, align 4, !tbaa !9
  %98 = sext i32 %97 to i64
  %99 = getelementptr inbounds i32, ptr %14, i64 %98
  %100 = load i32, ptr %99, align 4, !tbaa !9
  %101 = load ptr, ptr %3, align 8, !tbaa !5
  %102 = load i32, ptr %5, align 4, !tbaa !9
  %103 = sext i32 %102 to i64
  %104 = getelementptr inbounds i32, ptr %101, i64 %103
  store i32 %100, ptr %104, align 4, !tbaa !9
  br label %105

105:                                              ; preds = %96
  %106 = load i32, ptr %5, align 4, !tbaa !9
  %107 = add nsw i32 %106, 1
  store i32 %107, ptr %5, align 4, !tbaa !9
  br label %92, !llvm.loop !15

108:                                              ; preds = %92
  %109 = load i32, ptr %8, align 4, !tbaa !9
  %110 = mul nsw i32 %109, 10
  store i32 %110, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 40, ptr %10) #4
  br label %18, !llvm.loop !16

111:                                              ; preds = %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  %112 = load ptr, ptr %6, align 8
  call void @llvm.stackrestore.p0(ptr %112)
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #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 nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #2

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 = { nocallback nofree nosync nounwind willreturn }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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/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: nounwind uwtable
declare dso_local i32 @find_largest_number(ptr noundef, i32 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: nounwind uwtable
define dso_local void @radix_sort(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = alloca [10 x i32], align 16
  %4 = zext i32 %1 to i64
  %5 = alloca i32, i64 %4, align 16
  %6 = tail call i32 @find_largest_number(ptr noundef %0, i32 noundef %1)
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.lr.ph42, label %._crit_edge43

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

.lr.ph42.split.us.preheader:                      ; preds = %.lr.ph42
  %9 = shl nuw nsw i64 %4, 2
  %.phi.trans.insert89 = getelementptr inbounds i8, ptr %3, i64 36
  %.phi.trans.insert87 = getelementptr inbounds i8, ptr %3, i64 32
  %.phi.trans.insert85 = getelementptr inbounds i8, ptr %3, i64 28
  %.phi.trans.insert83 = getelementptr inbounds i8, ptr %3, i64 24
  %.phi.trans.insert81 = getelementptr inbounds i8, ptr %3, i64 20
  %.phi.trans.insert79 = getelementptr inbounds i8, ptr %3, i64 16
  %.phi.trans.insert77 = getelementptr inbounds i8, ptr %3, i64 12
  %.phi.trans.insert75 = getelementptr inbounds i8, ptr %3, i64 8
  %.phi.trans.insert = getelementptr inbounds i8, ptr %3, i64 4
  %10 = getelementptr inbounds i8, ptr %3, i64 4
  %11 = getelementptr inbounds i8, ptr %3, i64 8
  %12 = getelementptr inbounds i8, ptr %3, i64 12
  %13 = getelementptr inbounds i8, ptr %3, i64 16
  %14 = getelementptr inbounds i8, ptr %3, i64 20
  %15 = getelementptr inbounds i8, ptr %3, i64 24
  %16 = getelementptr inbounds i8, ptr %3, i64 28
  %17 = getelementptr inbounds i8, ptr %3, i64 32
  %18 = getelementptr inbounds i8, ptr %3, i64 36
  br label %.lr.ph.us.preheader

.lr.ph.us.preheader:                              ; preds = %._crit_edge.us, %.lr.ph42.split.us.preheader
  %.03040.us = phi i32 [ %19, %._crit_edge.us ], [ 1, %.lr.ph42.split.us.preheader ]
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %3) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(40) %3, i8 0, i64 40, i1 false)
  br label %.lr.ph.us

._crit_edge.us:                                   ; preds = %.preheader32.us
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 4 %0, ptr nonnull align 16 %5, i64 %9, i1 false), !tbaa !5
  %19 = mul nuw nsw i32 %.03040.us, 10
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %3) #4
  %20 = udiv i32 %6, %19
  %21 = icmp sgt i32 %20, 0
  br i1 %21, label %.lr.ph.us.preheader, label %._crit_edge43, !llvm.loop !9

.preheader32.us:                                  ; preds = %.preheader33.us, %.preheader32.us
  %indvars.iv68 = phi i64 [ %4, %.preheader33.us ], [ %indvars.iv.next69, %.preheader32.us ]
  %indvars.iv.next69 = add nsw i64 %indvars.iv68, -1
  %22 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv.next69
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = sdiv i32 %23, %.03040.us
  %25 = srem i32 %24, 10
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [10 x i32], ptr %3, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = add nsw i32 %28, -1
  store i32 %29, ptr %27, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds i32, ptr %5, i64 %30
  store i32 %23, ptr %31, align 4, !tbaa !5
  %32 = icmp sgt i64 %indvars.iv68, 1
  br i1 %32, label %.preheader32.us, label %._crit_edge.us, !llvm.loop !11

.lr.ph.us:                                        ; preds = %.lr.ph.us.preheader, %.lr.ph.us
  %indvars.iv = phi i64 [ 0, %.lr.ph.us.preheader ], [ %indvars.iv.next, %.lr.ph.us ]
  %33 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = sdiv i32 %34, %.03040.us
  %36 = srem i32 %35, 10
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [10 x i32], ptr %3, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %38, 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 %.preheader33.us, label %.lr.ph.us, !llvm.loop !12

.preheader33.us:                                  ; preds = %.lr.ph.us
  %.pre90 = load i32, ptr %.phi.trans.insert89, align 4, !tbaa !5
  %.pre88 = load i32, ptr %.phi.trans.insert87, align 16, !tbaa !5
  %.pre86 = load i32, ptr %.phi.trans.insert85, align 4, !tbaa !5
  %.pre84 = load i32, ptr %.phi.trans.insert83, align 8, !tbaa !5
  %.pre82 = load i32, ptr %.phi.trans.insert81, align 4, !tbaa !5
  %.pre80 = load i32, ptr %.phi.trans.insert79, align 16, !tbaa !5
  %.pre78 = load i32, ptr %.phi.trans.insert77, align 4, !tbaa !5
  %.pre76 = load i32, ptr %.phi.trans.insert75, align 8, !tbaa !5
  %.pre74 = load i32, ptr %.phi.trans.insert, align 4, !tbaa !5
  %.pre = load i32, ptr %3, align 16, !tbaa !5
  %41 = add nsw i32 %.pre74, %.pre
  store i32 %41, ptr %10, align 4, !tbaa !5
  %42 = add nsw i32 %.pre76, %41
  store i32 %42, ptr %11, align 8, !tbaa !5
  %43 = add nsw i32 %.pre78, %42
  store i32 %43, ptr %12, align 4, !tbaa !5
  %44 = add nsw i32 %.pre80, %43
  store i32 %44, ptr %13, align 16, !tbaa !5
  %45 = add nsw i32 %.pre82, %44
  store i32 %45, ptr %14, align 4, !tbaa !5
  %46 = add nsw i32 %.pre84, %45
  store i32 %46, ptr %15, align 8, !tbaa !5
  %47 = add nsw i32 %.pre86, %46
  store i32 %47, ptr %16, align 4, !tbaa !5
  %48 = add nsw i32 %.pre88, %47
  store i32 %48, ptr %17, align 16, !tbaa !5
  %49 = add nsw i32 %.pre90, %48
  store i32 %49, ptr %18, align 4, !tbaa !5
  br label %.preheader32.us

.preheader33:                                     ; preds = %.lr.ph42, %.preheader33
  %.03040 = phi i32 [ %50, %.preheader33 ], [ 1, %.lr.ph42 ]
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %3) #4
  %50 = mul nuw nsw i32 %.03040, 10
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %3) #4
  %51 = udiv i32 %6, %50
  %52 = icmp sgt i32 %51, 0
  br i1 %52, label %.preheader33, label %._crit_edge43, !llvm.loop !9

._crit_edge43:                                    ; preds = %.preheader33, %._crit_edge.us, %2
  ret void
}

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

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

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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !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: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,MemCpyOptPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass