; LLVM IR from erthink/libmdbx :: src (pnl)

; 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: nocallback nofree nosync nounwind willreturn memory(none)
declare i64 @llvm.expect.i64(i64, i64) #0

; Function Attrs: hot noinline nounwind uwtable
define dso_local void @pnl_sort_nochk(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds i32, ptr %3, i64 0
  %5 = load i32, ptr %4, align 4, !tbaa !9
  %6 = zext i32 %5 to i64
  %7 = icmp ult i64 %6, 142
  %8 = xor i1 %7, true
  %9 = xor i1 %8, true
  %10 = zext i1 %9 to i32
  %11 = sext i32 %10 to i64
  %12 = call i64 @llvm.expect.i64(i64 %11, i64 1)
  %13 = icmp ne i64 %12, 0
  br i1 %13, label %29, label %14

14:                                               ; preds = %1
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = getelementptr inbounds i32, ptr %15, i64 1
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds i32, ptr %17, i64 0
  %19 = load i32, ptr %18, align 4, !tbaa !9
  %20 = zext i32 %19 to i64
  %21 = call zeroext i1 @pgno_radixsort(ptr noundef %16, i64 noundef %20) #3
  %22 = xor i1 %21, true
  %23 = xor i1 %22, true
  %24 = xor i1 %23, true
  %25 = zext i1 %24 to i32
  %26 = sext i32 %25 to i64
  %27 = call i64 @llvm.expect.i64(i64 %26, i64 0)
  %28 = icmp ne i64 %27, 0
  br i1 %28, label %29, label %39

29:                                               ; preds = %14, %1
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = getelementptr inbounds i32, ptr %30, i64 1
  %32 = load ptr, ptr %2, align 8, !tbaa !5
  %33 = load ptr, ptr %2, align 8, !tbaa !5
  %34 = getelementptr inbounds i32, ptr %33, i64 0
  %35 = load i32, ptr %34, align 4, !tbaa !9
  %36 = zext i32 %35 to i64
  %37 = add i64 %36, 1
  %38 = getelementptr inbounds i32, ptr %32, i64 %37
  call void @pgno_sort(ptr noundef %31, ptr noundef %38) #3
  br label %39

39:                                               ; preds = %29, %14
  ret void
}

; Function Attrs: hot nounwind uwtable
declare hidden zeroext i1 @pgno_radixsort(ptr noundef, i64 noundef) #2

; Function Attrs: hot nounwind uwtable
declare hidden void @pgno_sort(ptr noalias noundef, ptr noalias noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(none) }
attributes #1 = { hot noinline 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 = { hot 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 = { hot }

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


; 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: hot noinline nounwind uwtable
define dso_local void @pnl_sort_nochk(ptr noundef %0) local_unnamed_addr #0 {
  %2 = load i32, ptr %0, align 4, !tbaa !5
  %3 = icmp ult i32 %2, 142
  br i1 %3, label %8, label %4, !prof !9

4:                                                ; preds = %1
  %5 = zext i32 %2 to i64
  %6 = getelementptr inbounds i8, ptr %0, i64 4
  %7 = tail call zeroext i1 @pgno_radixsort(ptr noundef nonnull %6, i64 noundef %5) #2
  br i1 %7, label %14, label %._crit_edge, !prof !9

._crit_edge:                                      ; preds = %4
  %.pre = load i32, ptr %0, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %._crit_edge, %1
  %9 = phi i32 [ %.pre, %._crit_edge ], [ %2, %1 ]
  %10 = getelementptr inbounds i8, ptr %0, i64 4
  %11 = zext i32 %9 to i64
  %12 = getelementptr inbounds i32, ptr %0, i64 %11
  %13 = getelementptr inbounds i8, ptr %12, i64 4
  tail call void @pgno_sort(ptr noundef nonnull %10, ptr noundef nonnull %13) #2
  br label %14

14:                                               ; preds = %8, %4
  ret void
}

; Function Attrs: hot nounwind uwtable
declare hidden zeroext i1 @pgno_radixsort(ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: hot nounwind uwtable
declare hidden void @pgno_sort(ptr noalias noundef, ptr noalias noundef) local_unnamed_addr #1

attributes #0 = { hot noinline 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 = { hot 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 = { hot }

!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 = !{!"branch_weights", !"expected", i32 2000, i32 1}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,LowerExpectIntrinsicPass,SROAPass,TailCallElimPass