; LLVM IR from GuillaumeHolley/BloomFilterTrie :: src (quicksort)

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

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @median3(ptr noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef) #1

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

; Function Attrs: nounwind willreturn memory(read)
declare i32 @memcmp(ptr noundef, ptr noundef, i64 noundef) #3

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

; Function Attrs: nounwind uwtable
declare dso_local void @manualSort(ptr noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @quicksort(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef %4) #1 {
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  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 i32 %3, ptr %9, align 4, !tbaa !9
  store ptr %4, ptr %10, align 8, !tbaa !5
  %14 = load i32, ptr %9, align 4, !tbaa !9
  %15 = load i32, ptr %8, align 4, !tbaa !9
  %16 = sub nsw i32 %14, %15
  %17 = add nsw i32 %16, 1
  %18 = icmp sle i32 %17, 3
  br i1 %18, label %19, label %25

19:                                               ; preds = %5
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = load i32, ptr %7, align 4, !tbaa !9
  %22 = load i32, ptr %8, align 4, !tbaa !9
  %23 = load i32, ptr %9, align 4, !tbaa !9
  %24 = load ptr, ptr %10, align 8, !tbaa !5
  call void @manualSort(ptr noundef %20, i32 noundef %21, i32 noundef %22, i32 noundef %23, ptr noundef %24)
  br label %130

25:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = load i32, ptr %7, align 4, !tbaa !9
  %28 = load i32, ptr %8, align 4, !tbaa !9
  %29 = load i32, ptr %9, align 4, !tbaa !9
  %30 = load ptr, ptr %10, align 8, !tbaa !5
  %31 = call ptr @median3(ptr noundef %26, i32 noundef %27, i32 noundef %28, i32 noundef %29, ptr noundef %30)
  store ptr %31, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %32 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %32, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %33 = load i32, ptr %9, align 4, !tbaa !9
  %34 = sub nsw i32 %33, 1
  store i32 %34, ptr %13, align 4, !tbaa !9
  br label %35

35:                                               ; preds = %93, %25
  br label %36

36:                                               ; preds = %35
  br label %37

37:                                               ; preds = %50, %36
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = load i32, ptr %12, align 4, !tbaa !9
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %12, align 4, !tbaa !9
  %41 = load i32, ptr %7, align 4, !tbaa !9
  %42 = mul nsw i32 %40, %41
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds i8, ptr %38, i64 %43
  %45 = load ptr, ptr %11, align 8, !tbaa !5
  %46 = load i32, ptr %7, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  %48 = call i32 @memcmp(ptr noundef %44, ptr noundef %45, i64 noundef %47) #5
  %49 = icmp slt i32 %48, 0
  br i1 %49, label %50, label %51

50:                                               ; preds = %37
  br label %37, !llvm.loop !11

51:                                               ; preds = %37
  br label %52

52:                                               ; preds = %65, %51
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = load i32, ptr %13, align 4, !tbaa !9
  %55 = add nsw i32 %54, -1
  store i32 %55, ptr %13, align 4, !tbaa !9
  %56 = load i32, ptr %7, align 4, !tbaa !9
  %57 = mul nsw i32 %55, %56
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds i8, ptr %53, i64 %58
  %60 = load ptr, ptr %11, align 8, !tbaa !5
  %61 = load i32, ptr %7, align 4, !tbaa !9
  %62 = sext i32 %61 to i64
  %63 = call i32 @memcmp(ptr noundef %59, ptr noundef %60, i64 noundef %62) #5
  %64 = icmp sgt i32 %63, 0
  br i1 %64, label %65, label %66

65:                                               ; preds = %52
  br label %52, !llvm.loop !13

66:                                               ; preds = %52
  %67 = load i32, ptr %12, align 4, !tbaa !9
  %68 = load i32, ptr %13, align 4, !tbaa !9
  %69 = icmp slt i32 %67, %68
  br i1 %69, label %70, label %92

70:                                               ; preds = %66
  %71 = load ptr, ptr %6, align 8, !tbaa !5
  %72 = load i32, ptr %12, align 4, !tbaa !9
  %73 = load i32, ptr %7, align 4, !tbaa !9
  %74 = mul nsw i32 %72, %73
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds i8, ptr %71, i64 %75
  %77 = load ptr, ptr %6, align 8, !tbaa !5
  %78 = load i32, ptr %13, align 4, !tbaa !9
  %79 = load i32, ptr %7, align 4, !tbaa !9
  %80 = mul nsw i32 %78, %79
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds i8, ptr %77, i64 %81
  %83 = load i32, ptr %7, align 4, !tbaa !9
  call void @swap_mem_uint8_t(ptr noundef %76, ptr noundef %82, i32 noundef %83)
  %84 = load ptr, ptr %10, align 8, !tbaa !5
  %85 = load i32, ptr %12, align 4, !tbaa !9
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds i32, ptr %84, i64 %86
  %88 = load ptr, ptr %10, 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
  call void @swap_mem_int(ptr noundef %87, ptr noundef %91)
  br label %93

92:                                               ; preds = %66
  br label %94

93:                                               ; preds = %70
  br label %35

94:                                               ; preds = %92
  %95 = load ptr, ptr %6, align 8, !tbaa !5
  %96 = load i32, ptr %12, align 4, !tbaa !9
  %97 = load i32, ptr %7, align 4, !tbaa !9
  %98 = mul nsw i32 %96, %97
  %99 = sext i32 %98 to i64
  %100 = getelementptr inbounds i8, ptr %95, i64 %99
  %101 = load ptr, ptr %6, align 8, !tbaa !5
  %102 = load i32, ptr %9, align 4, !tbaa !9
  %103 = sub nsw i32 %102, 1
  %104 = load i32, ptr %7, align 4, !tbaa !9
  %105 = mul nsw i32 %103, %104
  %106 = sext i32 %105 to i64
  %107 = getelementptr inbounds i8, ptr %101, i64 %106
  %108 = load i32, ptr %7, align 4, !tbaa !9
  call void @swap_mem_uint8_t(ptr noundef %100, ptr noundef %107, i32 noundef %108)
  %109 = load ptr, ptr %10, align 8, !tbaa !5
  %110 = load i32, ptr %12, align 4, !tbaa !9
  %111 = sext i32 %110 to i64
  %112 = getelementptr inbounds i32, ptr %109, i64 %111
  %113 = load ptr, ptr %10, align 8, !tbaa !5
  %114 = load i32, ptr %9, align 4, !tbaa !9
  %115 = sub nsw i32 %114, 1
  %116 = sext i32 %115 to i64
  %117 = getelementptr inbounds i32, ptr %113, i64 %116
  call void @swap_mem_int(ptr noundef %112, ptr noundef %117)
  %118 = load ptr, ptr %6, align 8, !tbaa !5
  %119 = load i32, ptr %7, align 4, !tbaa !9
  %120 = load i32, ptr %8, align 4, !tbaa !9
  %121 = load i32, ptr %12, align 4, !tbaa !9
  %122 = sub nsw i32 %121, 1
  %123 = load ptr, ptr %10, align 8, !tbaa !5
  call void @quicksort(ptr noundef %118, i32 noundef %119, i32 noundef %120, i32 noundef %122, ptr noundef %123)
  %124 = load ptr, ptr %6, align 8, !tbaa !5
  %125 = load i32, ptr %7, align 4, !tbaa !9
  %126 = load i32, ptr %12, align 4, !tbaa !9
  %127 = add nsw i32 %126, 1
  %128 = load i32, ptr %9, align 4, !tbaa !9
  %129 = load ptr, ptr %10, align 8, !tbaa !5
  call void @quicksort(ptr noundef %124, i32 noundef %125, i32 noundef %127, i32 noundef %128, ptr noundef %129)
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  br label %130

130:                                              ; preds = %94, %19
  ret void
}

attributes #0 = { inlinehint 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 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nounwind willreturn memory(read) "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 }
attributes #5 = { nounwind willreturn memory(read) }

!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}


; 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: inlinehint nounwind uwtable
declare dso_local void @swap_mem_uint8_t(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

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

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @memcmp(ptr nocapture noundef, ptr nocapture noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local void @manualSort(ptr noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @quicksort(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef %4) local_unnamed_addr #1 {
  %6 = sub nsw i32 %3, %2
  %7 = icmp slt i32 %6, 3
  br i1 %7, label %tailrecurse._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %5
  %8 = add nsw i32 %3, -1
  %9 = sext i32 %1 to i64
  %10 = mul nsw i32 %8, %1
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds i8, ptr %0, i64 %11
  %13 = sext i32 %8 to i64
  %14 = getelementptr inbounds i32, ptr %4, i64 %13
  br label %15

tailrecurse._crit_edge:                           ; preds = %tailrecurse, %5
  %.tr63.lcssa = phi i32 [ %2, %5 ], [ %42, %tailrecurse ]
  tail call void @manualSort(ptr noundef %0, i32 noundef %1, i32 noundef %.tr63.lcssa, i32 noundef %3, ptr noundef %4)
  ret void

15:                                               ; preds = %.lr.ph, %tailrecurse
  %.tr6370 = phi i32 [ %2, %.lr.ph ], [ %42, %tailrecurse ]
  %16 = tail call ptr @median3(ptr noundef %0, i32 noundef %1, i32 noundef %.tr6370, i32 noundef %3, ptr noundef %4)
  br label %17

17:                                               ; preds = %32, %15
  %.057 = phi i32 [ %.tr6370, %15 ], [ %33, %32 ]
  %.0 = phi i32 [ %8, %15 ], [ %34, %32 ]
  %18 = sext i32 %.057 to i64
  br label %19

19:                                               ; preds = %19, %17
  %indvars.iv = phi i64 [ %indvars.iv.next, %19 ], [ %18, %17 ]
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %20 = mul nsw i64 %indvars.iv.next, %9
  %21 = getelementptr inbounds i8, ptr %0, i64 %20
  %22 = tail call i32 @memcmp(ptr noundef %21, ptr noundef %16, i64 noundef %9) #3
  %23 = icmp slt i32 %22, 0
  br i1 %23, label %19, label %.preheader, !llvm.loop !5

.preheader:                                       ; preds = %19
  %24 = sext i32 %.0 to i64
  br label %25

25:                                               ; preds = %.preheader, %25
  %indvars.iv76 = phi i64 [ %24, %.preheader ], [ %indvars.iv.next77, %25 ]
  %indvars.iv.next77 = add nsw i64 %indvars.iv76, -1
  %26 = mul nsw i64 %indvars.iv.next77, %9
  %27 = getelementptr inbounds i8, ptr %0, i64 %26
  %28 = tail call i32 @memcmp(ptr noundef %27, ptr noundef %16, i64 noundef %9) #3
  %29 = icmp sgt i32 %28, 0
  br i1 %29, label %25, label %30, !llvm.loop !7

30:                                               ; preds = %25
  %31 = icmp slt i64 %indvars.iv.next, %indvars.iv.next77
  br i1 %31, label %32, label %tailrecurse

32:                                               ; preds = %30
  %33 = trunc nsw i64 %indvars.iv.next to i32
  %34 = trunc nsw i64 %indvars.iv.next77 to i32
  tail call void @swap_mem_uint8_t(ptr noundef %21, ptr noundef %27, i32 noundef %1)
  %sext79 = shl i64 %indvars.iv.next, 32
  %35 = ashr exact i64 %sext79, 30
  %36 = getelementptr inbounds i8, ptr %4, i64 %35
  %sext80 = shl i64 %indvars.iv.next77, 32
  %37 = ashr exact i64 %sext80, 30
  %38 = getelementptr inbounds i8, ptr %4, i64 %37
  tail call void @swap_mem_int(ptr noundef %36, ptr noundef %38)
  br label %17

tailrecurse:                                      ; preds = %30
  %39 = trunc nsw i64 %indvars.iv to i32
  tail call void @swap_mem_uint8_t(ptr noundef %21, ptr noundef %12, i32 noundef %1)
  %sext = shl i64 %indvars.iv.next, 32
  %40 = ashr exact i64 %sext, 30
  %41 = getelementptr inbounds i8, ptr %4, i64 %40
  tail call void @swap_mem_int(ptr noundef %41, ptr noundef %14)
  tail call void @quicksort(ptr noundef %0, i32 noundef %1, i32 noundef %.tr6370, i32 noundef %39, ptr noundef %4)
  %42 = add nsw i32 %39, 2
  %43 = sub nsw i32 %3, %42
  %44 = icmp slt i32 %43, 3
  br i1 %44, label %tailrecurse._crit_edge, label %15
}

attributes #0 = { inlinehint 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 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 #2 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 willreturn memory(read) }

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}


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