; 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_first8(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 i8, ptr %11, i64 %12
  store ptr %13, ptr %9, align 8, !tbaa !5
  br label %14

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

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 i8, ptr %20, align 1, !tbaa !11
  %22 = sext i8 %21 to i32
  %23 = load ptr, ptr %9, align 8, !tbaa !5
  %24 = load i64, ptr %10, align 8, !tbaa !9
  %25 = sub i64 0, %24
  %26 = getelementptr inbounds i8, ptr %23, i64 %25
  %27 = load i8, ptr %26, align 1, !tbaa !11
  %28 = sext i8 %27 to i32
  %29 = icmp sgt i32 %22, %28
  %30 = zext i1 %29 to i32
  %31 = icmp sle i32 %30, 0
  br i1 %31, label %32, label %37

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

37:                                               ; preds = %32, %17
  %38 = load i64, ptr %10, align 8, !tbaa !9
  %39 = load i64, ptr %7, align 8, !tbaa !9
  %40 = sub i64 %39, %38
  store i64 %40, ptr %7, align 8, !tbaa !9
  br label %14, !llvm.loop !12

41:                                               ; preds = %14
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = load i8, ptr %42, align 1, !tbaa !11
  %44 = sext i8 %43 to i32
  %45 = load ptr, ptr %9, align 8, !tbaa !5
  %46 = getelementptr inbounds i8, ptr %45, i64 -1
  %47 = load i8, ptr %46, align 1, !tbaa !11
  %48 = sext i8 %47 to i32
  %49 = icmp sgt i32 %44, %48
  %50 = zext i1 %49 to i32
  %51 = icmp sle i32 %50, 0
  br i1 %51, label %52, label %55

52:                                               ; preds = %41
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  %54 = getelementptr inbounds i8, ptr %53, i32 -1
  store ptr %54, ptr %9, align 8, !tbaa !5
  br label %55

55:                                               ; preds = %52, %41
  %56 = load ptr, ptr %9, align 8, !tbaa !5
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = ptrtoint ptr %56 to i64
  %59 = ptrtoint ptr %57 to i64
  %60 = sub i64 %58, %59
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  ret i64 %60
}

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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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 i64 @monobound_binary_first8(ptr noundef %0, ptr nocapture noundef readonly %1, i64 noundef %2, ptr nocapture noundef readnone %3) local_unnamed_addr #0 {
  %5 = getelementptr inbounds i8, ptr %0, i64 %2
  %6 = icmp ugt i64 %2, 1
  %.pre = load i8, ptr %1, align 1, !tbaa !5
  br i1 %6, label %.lr.ph, label %._crit_edge

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

._crit_edge:                                      ; preds = %.lr.ph, %4
  %.015.lcssa = phi ptr [ %5, %4 ], [ %spec.select, %.lr.ph ]
  %14 = getelementptr inbounds i8, ptr %.015.lcssa, i64 -1
  %15 = load i8, ptr %14, align 1, !tbaa !5
  %16 = icmp sgt i8 %.pre, %15
  %spec.select16 = select i1 %16, ptr %.015.lcssa, ptr %14
  %17 = ptrtoint ptr %spec.select16 to i64
  %18 = ptrtoint ptr %0 to i64
  %19 = sub i64 %17, %18
  ret i64 %19
}

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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


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