; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: nounwind uwtable
define dso_local i64 @monobound_binary_first128(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, 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
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = load i64, ptr %7, align 8, !tbaa !9
  %13 = getelementptr inbounds x86_fp80, ptr %11, i64 %12
  store ptr %13, ptr %9, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %35, %4
  %15 = load i64, ptr %7, align 8, !tbaa !9
  %16 = icmp ugt i64 %15, 1
  br i1 %16, label %17, label %39

17:                                               ; preds = %14
  %18 = load i64, ptr %7, align 8, !tbaa !9
  %19 = udiv i64 %18, 2
  store i64 %19, ptr %10, align 8, !tbaa !9
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = load x86_fp80, ptr %20, align 16, !tbaa !11
  %22 = load ptr, ptr %9, align 8, !tbaa !5
  %23 = load i64, ptr %10, align 8, !tbaa !9
  %24 = sub i64 0, %23
  %25 = getelementptr inbounds x86_fp80, ptr %22, i64 %24
  %26 = load x86_fp80, ptr %25, align 16, !tbaa !11
  %27 = fcmp ogt x86_fp80 %21, %26
  %28 = zext i1 %27 to i32
  %29 = icmp sle i32 %28, 0
  br i1 %29, label %30, label %35

30:                                               ; preds = %17
  %31 = load i64, ptr %10, align 8, !tbaa !9
  %32 = load ptr, ptr %9, align 8, !tbaa !5
  %33 = sub i64 0, %31
  %34 = getelementptr inbounds x86_fp80, ptr %32, i64 %33
  store ptr %34, ptr %9, align 8, !tbaa !5
  br label %35

35:                                               ; preds = %30, %17
  %36 = load i64, ptr %10, align 8, !tbaa !9
  %37 = load i64, ptr %7, align 8, !tbaa !9
  %38 = sub i64 %37, %36
  store i64 %38, ptr %7, align 8, !tbaa !9
  br label %14, !llvm.loop !13

39:                                               ; preds = %14
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = load x86_fp80, ptr %40, align 16, !tbaa !11
  %42 = load ptr, ptr %9, align 8, !tbaa !5
  %43 = getelementptr inbounds x86_fp80, ptr %42, i64 -1
  %44 = load x86_fp80, ptr %43, align 16, !tbaa !11
  %45 = fcmp ogt x86_fp80 %41, %44
  %46 = zext i1 %45 to i32
  %47 = icmp sle i32 %46, 0
  br i1 %47, label %48, label %51

48:                                               ; preds = %39
  %49 = load ptr, ptr %9, align 8, !tbaa !5
  %50 = getelementptr inbounds x86_fp80, ptr %49, i32 -1
  store ptr %50, ptr %9, align 8, !tbaa !5
  br label %51

51:                                               ; preds = %48, %39
  %52 = load ptr, ptr %9, align 8, !tbaa !5
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = ptrtoint ptr %52 to i64
  %55 = ptrtoint ptr %53 to i64
  %56 = sub i64 %54, %55
  %57 = sdiv exact i64 %56, 16
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  ret i64 %57
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long double", !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 range(i64 -576460752303423488, 576460752303423488) i64 @monobound_binary_first128(ptr noundef %0, ptr nocapture noundef readonly %1, i64 noundef %2, ptr nocapture noundef readnone %3) local_unnamed_addr #0 {
  %5 = getelementptr inbounds x86_fp80, ptr %0, i64 %2
  %6 = icmp ugt i64 %2, 1
  %.pre = load x86_fp80, ptr %1, align 16, !tbaa !5
  br i1 %6, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %4, %.lr.ph
  %.017 = phi i64 [ %12, %.lr.ph ], [ %2, %4 ]
  %.01516 = phi ptr [ %.1, %.lr.ph ], [ %5, %4 ]
  %7 = lshr i64 %.017, 1
  %8 = sub nsw i64 0, %7
  %9 = getelementptr inbounds x86_fp80, ptr %.01516, i64 %8
  %10 = load x86_fp80, ptr %9, align 16, !tbaa !5
  %11 = fcmp ogt x86_fp80 %.pre, %10
  %.1 = select i1 %11, ptr %.01516, ptr %9
  %12 = sub i64 %.017, %7
  %13 = icmp ugt i64 %12, 1
  br i1 %13, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %4
  %.015.lcssa = phi ptr [ %5, %4 ], [ %.1, %.lr.ph ]
  %14 = getelementptr inbounds i8, ptr %.015.lcssa, i64 -16
  %15 = load x86_fp80, ptr %14, align 16, !tbaa !5
  %16 = fcmp ogt x86_fp80 %.pre, %15
  %.2 = select i1 %16, ptr %.015.lcssa, ptr %14
  %17 = ptrtoint ptr %.2 to i64
  %18 = ptrtoint ptr %0 to i64
  %19 = sub i64 %17, %18
  %20 = ashr exact i64 %19, 4
  ret i64 %20
}

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

!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 = !{!"long double", !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,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass