; LLVM IR from AlgoGenesis/C :: Sorting Algorithms/Randomized Quick Sort (Program)

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

; Function Attrs: nounwind uwtable
declare dso_local void @swapElements(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @randomizedQuickSort(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 i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = 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
  %11 = load i32, ptr %5, align 4, !tbaa !9
  %12 = load i32, ptr %6, align 4, !tbaa !9
  %13 = icmp sge i32 %11, %12
  br i1 %13, label %14, label %15

14:                                               ; preds = %3
  br label %122

15:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %16 = load i32, ptr %5, align 4, !tbaa !9
  %17 = call i32 @rand() #3
  %18 = load i32, ptr %6, align 4, !tbaa !9
  %19 = load i32, ptr %5, align 4, !tbaa !9
  %20 = sub nsw i32 %18, %19
  %21 = srem i32 %17, %20
  %22 = add nsw i32 %16, %21
  store i32 %22, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = load i32, ptr %7, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds i32, ptr %23, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !9
  store i32 %27, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = load i32, ptr %5, align 4, !tbaa !9
  %30 = load i32, ptr %6, align 4, !tbaa !9
  %31 = load i32, ptr %8, align 4, !tbaa !9
  %32 = call i32 @findFirstGreater(ptr noundef %28, i32 noundef %29, i32 noundef %30, i32 noundef %31)
  store i32 %32, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = load i32, ptr %6, align 4, !tbaa !9
  %35 = load i32, ptr %5, align 4, !tbaa !9
  %36 = load i32, ptr %8, align 4, !tbaa !9
  %37 = call i32 @findFirstSmaller(ptr noundef %33, i32 noundef %34, i32 noundef %35, i32 noundef %36)
  store i32 %37, ptr %10, align 4, !tbaa !9
  br label %38

38:                                               ; preds = %42, %15
  %39 = load i32, ptr %9, align 4, !tbaa !9
  %40 = load i32, ptr %10, align 4, !tbaa !9
  %41 = icmp sle i32 %39, %40
  br i1 %41, label %42, label %61

42:                                               ; preds = %38
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = load i32, ptr %9, align 4, !tbaa !9
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds i32, ptr %43, i64 %45
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = load i32, ptr %10, align 4, !tbaa !9
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds i32, ptr %47, i64 %49
  call void @swapElements(ptr noundef %46, ptr noundef %50)
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = load i32, ptr %9, align 4, !tbaa !9
  %53 = load i32, ptr %6, align 4, !tbaa !9
  %54 = load i32, ptr %8, align 4, !tbaa !9
  %55 = call i32 @findFirstGreater(ptr noundef %51, i32 noundef %52, i32 noundef %53, i32 noundef %54)
  store i32 %55, ptr %9, align 4, !tbaa !9
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = load i32, ptr %10, align 4, !tbaa !9
  %58 = load i32, ptr %5, align 4, !tbaa !9
  %59 = load i32, ptr %8, align 4, !tbaa !9
  %60 = call i32 @findFirstSmaller(ptr noundef %56, i32 noundef %57, i32 noundef %58, i32 noundef %59)
  store i32 %60, ptr %10, align 4, !tbaa !9
  br label %38, !llvm.loop !11

61:                                               ; preds = %38
  %62 = load i32, ptr %7, align 4, !tbaa !9
  %63 = load i32, ptr %10, align 4, !tbaa !9
  %64 = icmp sgt i32 %62, %63
  br i1 %64, label %65, label %86

65:                                               ; preds = %61
  %66 = load i32, ptr %7, align 4, !tbaa !9
  %67 = load i32, ptr %9, align 4, !tbaa !9
  %68 = icmp sgt i32 %66, %67
  br i1 %68, label %69, label %86

69:                                               ; preds = %65
  %70 = load ptr, ptr %4, align 8, !tbaa !5
  %71 = load i32, ptr %9, align 4, !tbaa !9
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds i32, ptr %70, i64 %72
  %74 = load ptr, ptr %4, align 8, !tbaa !5
  %75 = load i32, ptr %7, align 4, !tbaa !9
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds i32, ptr %74, i64 %76
  call void @swapElements(ptr noundef %73, ptr noundef %77)
  %78 = load ptr, ptr %4, align 8, !tbaa !5
  %79 = load i32, ptr %5, align 4, !tbaa !9
  %80 = load i32, ptr %9, align 4, !tbaa !9
  %81 = sub nsw i32 %80, 1
  call void @randomizedQuickSort(ptr noundef %78, i32 noundef %79, i32 noundef %81)
  %82 = load ptr, ptr %4, align 8, !tbaa !5
  %83 = load i32, ptr %9, align 4, !tbaa !9
  %84 = add nsw i32 %83, 1
  %85 = load i32, ptr %6, align 4, !tbaa !9
  call void @randomizedQuickSort(ptr noundef %82, i32 noundef %84, i32 noundef %85)
  br label %121

86:                                               ; preds = %65, %61
  %87 = load i32, ptr %7, align 4, !tbaa !9
  %88 = load i32, ptr %10, align 4, !tbaa !9
  %89 = icmp slt i32 %87, %88
  br i1 %89, label %90, label %111

90:                                               ; preds = %86
  %91 = load i32, ptr %7, align 4, !tbaa !9
  %92 = load i32, ptr %9, align 4, !tbaa !9
  %93 = icmp slt i32 %91, %92
  br i1 %93, label %94, label %111

94:                                               ; preds = %90
  %95 = load ptr, ptr %4, align 8, !tbaa !5
  %96 = load i32, ptr %10, align 4, !tbaa !9
  %97 = sext i32 %96 to i64
  %98 = getelementptr inbounds i32, ptr %95, i64 %97
  %99 = load ptr, ptr %4, align 8, !tbaa !5
  %100 = load i32, ptr %7, align 4, !tbaa !9
  %101 = sext i32 %100 to i64
  %102 = getelementptr inbounds i32, ptr %99, i64 %101
  call void @swapElements(ptr noundef %98, ptr noundef %102)
  %103 = load ptr, ptr %4, align 8, !tbaa !5
  %104 = load i32, ptr %5, align 4, !tbaa !9
  %105 = load i32, ptr %10, align 4, !tbaa !9
  %106 = sub nsw i32 %105, 1
  call void @randomizedQuickSort(ptr noundef %103, i32 noundef %104, i32 noundef %106)
  %107 = load ptr, ptr %4, align 8, !tbaa !5
  %108 = load i32, ptr %10, align 4, !tbaa !9
  %109 = add nsw i32 %108, 1
  %110 = load i32, ptr %6, align 4, !tbaa !9
  call void @randomizedQuickSort(ptr noundef %107, i32 noundef %109, i32 noundef %110)
  br label %120

111:                                              ; preds = %90, %86
  %112 = load ptr, ptr %4, align 8, !tbaa !5
  %113 = load i32, ptr %5, align 4, !tbaa !9
  %114 = load i32, ptr %7, align 4, !tbaa !9
  %115 = sub nsw i32 %114, 1
  call void @randomizedQuickSort(ptr noundef %112, i32 noundef %113, i32 noundef %115)
  %116 = load ptr, ptr %4, align 8, !tbaa !5
  %117 = load i32, ptr %7, align 4, !tbaa !9
  %118 = add nsw i32 %117, 1
  %119 = load i32, ptr %6, align 4, !tbaa !9
  call void @randomizedQuickSort(ptr noundef %116, i32 noundef %118, i32 noundef %119)
  br label %120

120:                                              ; preds = %111, %94
  br label %121

121:                                              ; preds = %120, %69
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %122

122:                                              ; preds = %121, %14
  ret void
}

; Function Attrs: nounwind
declare i32 @rand() #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 = { 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 #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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; 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 @findFirstGreater(ptr noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @findFirstSmaller(ptr noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @swapElements(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @randomizedQuickSort(ptr noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %.not74 = icmp slt i32 %1, %2
  br i1 %.not74, label %.lr.ph77, label %tailrecurse._crit_edge

.lr.ph77:                                         ; preds = %3, %tailrecurse.backedge
  %.tr6875 = phi i32 [ %.tr68.be, %tailrecurse.backedge ], [ %1, %3 ]
  %4 = tail call i32 @rand() #2
  %5 = sub nsw i32 %2, %.tr6875
  %6 = srem i32 %4, %5
  %7 = add nsw i32 %6, %.tr6875
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds i32, ptr %0, i64 %8
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = tail call i32 @findFirstGreater(ptr noundef %0, i32 noundef %.tr6875, i32 noundef %2, i32 noundef %10)
  %12 = tail call i32 @findFirstSmaller(ptr noundef %0, i32 noundef %2, i32 noundef %.tr6875, i32 noundef %10)
  %.not6670 = icmp sgt i32 %11, %12
  br i1 %.not6670, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph77, %.lr.ph
  %.072 = phi i32 [ %18, %.lr.ph ], [ %12, %.lr.ph77 ]
  %.06271 = phi i32 [ %17, %.lr.ph ], [ %11, %.lr.ph77 ]
  %13 = sext i32 %.06271 to i64
  %14 = getelementptr inbounds i32, ptr %0, i64 %13
  %15 = sext i32 %.072 to i64
  %16 = getelementptr inbounds i32, ptr %0, i64 %15
  tail call void @swapElements(ptr noundef %14, ptr noundef %16)
  %17 = tail call i32 @findFirstGreater(ptr noundef %0, i32 noundef %.06271, i32 noundef %2, i32 noundef %10)
  %18 = tail call i32 @findFirstSmaller(ptr noundef %0, i32 noundef %.072, i32 noundef %.tr6875, i32 noundef %10)
  %.not66 = icmp sgt i32 %17, %18
  br i1 %.not66, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %.lr.ph77
  %.062.lcssa = phi i32 [ %11, %.lr.ph77 ], [ %17, %.lr.ph ]
  %.0.lcssa = phi i32 [ %12, %.lr.ph77 ], [ %18, %.lr.ph ]
  %19 = icmp sgt i32 %7, %.062.lcssa
  br i1 %19, label %tailrecurse.backedge.sink.split, label %23

tailrecurse.backedge.sink.split:                  ; preds = %._crit_edge, %23
  %.062.lcssa.sink81 = phi i32 [ %.0.lcssa, %23 ], [ %.062.lcssa, %._crit_edge ]
  %20 = sext i32 %.062.lcssa.sink81 to i64
  %21 = getelementptr inbounds i32, ptr %0, i64 %20
  tail call void @swapElements(ptr noundef %21, ptr noundef nonnull %9)
  br label %tailrecurse.backedge

tailrecurse.backedge:                             ; preds = %tailrecurse.backedge.sink.split, %23
  %.062.lcssa.sink = phi i32 [ %7, %23 ], [ %.062.lcssa.sink81, %tailrecurse.backedge.sink.split ]
  %22 = add nsw i32 %.062.lcssa.sink, -1
  tail call void @randomizedQuickSort(ptr noundef %0, i32 noundef %.tr6875, i32 noundef %22)
  %.tr68.be = add nsw i32 %.062.lcssa.sink, 1
  %.not = icmp slt i32 %.tr68.be, %2
  br i1 %.not, label %.lr.ph77, label %tailrecurse._crit_edge

23:                                               ; preds = %._crit_edge
  %24 = icmp slt i32 %7, %.0.lcssa
  br i1 %24, label %tailrecurse.backedge.sink.split, label %tailrecurse.backedge

tailrecurse._crit_edge:                           ; preds = %tailrecurse.backedge, %3
  ret void
}

; Function Attrs: nounwind
declare i32 @rand() local_unnamed_addr #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 = { 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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: ConstraintEliminationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass