; LLVM IR from Voultapher/sort-research-rs :: src/cpp/thirdparty/scandum (bench)

; 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 signext i16 @binary_median16(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !5
  br label %9

9:                                                ; preds = %35, %4
  %10 = load i64, ptr %7, align 8, !tbaa !9
  %11 = udiv i64 %10, 2
  store i64 %11, ptr %7, align 8, !tbaa !9
  %12 = icmp ne i64 %11, 0
  br i1 %12, label %13, label %36

13:                                               ; preds = %9
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = load i64, ptr %7, align 8, !tbaa !9
  %16 = getelementptr inbounds i16, ptr %14, i64 %15
  %17 = load i16, ptr %16, align 2, !tbaa !11
  %18 = sext i16 %17 to i32
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = load i64, ptr %7, align 8, !tbaa !9
  %21 = getelementptr inbounds i16, ptr %19, i64 %20
  %22 = load i16, ptr %21, align 2, !tbaa !11
  %23 = sext i16 %22 to i32
  %24 = icmp sgt i32 %18, %23
  %25 = zext i1 %24 to i32
  %26 = icmp sle i32 %25, 0
  br i1 %26, label %27, label %31

27:                                               ; preds = %13
  %28 = load i64, ptr %7, align 8, !tbaa !9
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds i16, ptr %29, i64 %28
  store ptr %30, ptr %5, align 8, !tbaa !5
  br label %35

31:                                               ; preds = %13
  %32 = load i64, ptr %7, align 8, !tbaa !9
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = getelementptr inbounds i16, ptr %33, i64 %32
  store ptr %34, ptr %6, align 8, !tbaa !5
  br label %35

35:                                               ; preds = %31, %27
  br label %9, !llvm.loop !13

36:                                               ; preds = %9
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = load i16, ptr %37, align 2, !tbaa !11
  %39 = sext i16 %38 to i32
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = load i16, ptr %40, align 2, !tbaa !11
  %42 = sext i16 %41 to i32
  %43 = icmp sgt i32 %39, %42
  %44 = zext i1 %43 to i32
  %45 = icmp sgt i32 %44, 0
  br i1 %45, label %46, label %50

46:                                               ; preds = %36
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = load i16, ptr %47, align 2, !tbaa !11
  %49 = sext i16 %48 to i32
  br label %54

50:                                               ; preds = %36
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = load i16, ptr %51, align 2, !tbaa !11
  %53 = sext i16 %52 to i32
  br label %54

54:                                               ; preds = %50, %46
  %55 = phi i32 [ %49, %46 ], [ %53, %50 ]
  %56 = trunc i32 %55 to i16
  ret i16 %56
}

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

!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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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: nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) uwtable
define dso_local signext i16 @binary_median16(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, i64 noundef %2, ptr nocapture noundef readnone %3) local_unnamed_addr #0 {
  %.not19 = icmp ult i64 %2, 2
  br i1 %.not19, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %4, %.lr.ph
  %.022 = phi ptr [ %.0., %.lr.ph ], [ %0, %4 ]
  %.01221 = phi i64 [ %5, %.lr.ph ], [ %2, %4 ]
  %.01320 = phi ptr [ %..013, %.lr.ph ], [ %1, %4 ]
  %5 = lshr i64 %.01221, 1
  %6 = getelementptr inbounds i16, ptr %.022, i64 %5
  %7 = load i16, ptr %6, align 2, !tbaa !5
  %8 = getelementptr inbounds i16, ptr %.01320, i64 %5
  %9 = load i16, ptr %8, align 2, !tbaa !5
  %10 = icmp sgt i16 %7, %9
  %..013 = select i1 %10, ptr %8, ptr %.01320
  %.0. = select i1 %10, ptr %.022, ptr %6
  %.not = icmp ult i64 %.01221, 4
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %4
  %.013.lcssa = phi ptr [ %1, %4 ], [ %..013, %.lr.ph ]
  %.0.lcssa = phi ptr [ %0, %4 ], [ %.0., %.lr.ph ]
  %11 = load i16, ptr %.0.lcssa, align 2, !tbaa !5
  %12 = load i16, ptr %.013.lcssa, align 2, !tbaa !5
  %. = tail call i16 @llvm.smax.i16(i16 %11, i16 %12)
  ret i16 %.
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i16 @llvm.smax.i16(i16, i16) #1

attributes #0 = { nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) 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 speculatable willreturn memory(none) }

!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 = !{!"short", !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: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass