; 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 void @tail_merge8(ptr noundef %0, ptr noundef %1, i64 noundef %2, i64 noundef %3, i64 noundef %4, ptr noundef %5) #1 {
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i64 %2, ptr %9, align 8, !tbaa !9
  store i64 %3, ptr %10, align 8, !tbaa !9
  store i64 %4, ptr %11, align 8, !tbaa !9
  store ptr %5, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #2
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = load i64, ptr %10, align 8, !tbaa !9
  %17 = getelementptr inbounds i8, ptr %15, i64 %16
  store ptr %17, ptr %14, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %65, %6
  %19 = load i64, ptr %11, align 8, !tbaa !9
  %20 = load i64, ptr %10, align 8, !tbaa !9
  %21 = icmp ult i64 %19, %20
  br i1 %21, label %22, label %26

22:                                               ; preds = %18
  %23 = load i64, ptr %11, align 8, !tbaa !9
  %24 = load i64, ptr %9, align 8, !tbaa !9
  %25 = icmp ule i64 %23, %24
  br label %26

26:                                               ; preds = %22, %18
  %27 = phi i1 [ false, %18 ], [ %25, %22 ]
  br i1 %27, label %28, label %68

28:                                               ; preds = %26
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %29, ptr %13, align 8, !tbaa !5
  br label %30

30:                                               ; preds = %60, %28
  %31 = load ptr, ptr %13, align 8, !tbaa !5
  %32 = load i64, ptr %11, align 8, !tbaa !9
  %33 = getelementptr inbounds i8, ptr %31, i64 %32
  %34 = load ptr, ptr %14, align 8, !tbaa !5
  %35 = icmp ult ptr %33, %34
  br i1 %35, label %36, label %65

36:                                               ; preds = %30
  %37 = load ptr, ptr %13, align 8, !tbaa !5
  %38 = load i64, ptr %11, align 8, !tbaa !9
  %39 = mul i64 %38, 2
  %40 = getelementptr inbounds i8, ptr %37, i64 %39
  %41 = load ptr, ptr %14, align 8, !tbaa !5
  %42 = icmp ult ptr %40, %41
  br i1 %42, label %43, label %50

43:                                               ; preds = %36
  %44 = load ptr, ptr %13, align 8, !tbaa !5
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  %46 = load i64, ptr %11, align 8, !tbaa !9
  %47 = mul i64 %46, 2
  %48 = load i64, ptr %11, align 8, !tbaa !9
  %49 = load ptr, ptr %12, align 8, !tbaa !5
  call void @partial_backward_merge8(ptr noundef %44, ptr noundef %45, i64 noundef %47, i64 noundef %48, ptr noundef %49)
  br label %60

50:                                               ; preds = %36
  %51 = load ptr, ptr %13, align 8, !tbaa !5
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  %53 = load ptr, ptr %14, align 8, !tbaa !5
  %54 = load ptr, ptr %13, align 8, !tbaa !5
  %55 = ptrtoint ptr %53 to i64
  %56 = ptrtoint ptr %54 to i64
  %57 = sub i64 %55, %56
  %58 = load i64, ptr %11, align 8, !tbaa !9
  %59 = load ptr, ptr %12, align 8, !tbaa !5
  call void @partial_backward_merge8(ptr noundef %51, ptr noundef %52, i64 noundef %57, i64 noundef %58, ptr noundef %59)
  br label %65

60:                                               ; preds = %43
  %61 = load i64, ptr %11, align 8, !tbaa !9
  %62 = mul i64 %61, 2
  %63 = load ptr, ptr %13, align 8, !tbaa !5
  %64 = getelementptr inbounds i8, ptr %63, i64 %62
  store ptr %64, ptr %13, align 8, !tbaa !5
  br label %30, !llvm.loop !11

65:                                               ; preds = %50, %30
  %66 = load i64, ptr %11, align 8, !tbaa !9
  %67 = mul i64 %66, 2
  store i64 %67, ptr %11, align 8, !tbaa !9
  br label %18, !llvm.loop !13

68:                                               ; preds = %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #2
  ret void
}

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

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 = 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: nounwind uwtable
define dso_local void @tail_merge8(ptr noundef %0, ptr noundef %1, i64 noundef %2, i64 noundef %3, i64 noundef %4, ptr noundef %5) local_unnamed_addr #0 {
  %7 = getelementptr inbounds i8, ptr %0, i64 %3
  %8 = icmp ult i64 %4, %3
  %9 = icmp ule i64 %4, %2
  %10 = and i1 %8, %9
  br i1 %10, label %.preheader.lr.ph, label %._crit_edge

.preheader.lr.ph:                                 ; preds = %6
  %11 = ptrtoint ptr %7 to i64
  br label %.preheader

.preheader:                                       ; preds = %.preheader.lr.ph, %.loopexit
  %.031 = phi i64 [ %4, %.preheader.lr.ph ], [ %13, %.loopexit ]
  %12 = icmp slt i64 %.031, %3
  %13 = shl i64 %.031, 1
  br i1 %12, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader, %16
  %.02630 = phi ptr [ %14, %16 ], [ %0, %.preheader ]
  %14 = getelementptr inbounds i8, ptr %.02630, i64 %13
  %15 = icmp ult ptr %14, %7
  br i1 %15, label %16, label %19

16:                                               ; preds = %.lr.ph
  tail call void @partial_backward_merge8(ptr noundef %.02630, ptr noundef %1, i64 noundef %13, i64 noundef %.031, ptr noundef %5)
  %17 = getelementptr inbounds i8, ptr %14, i64 %.031
  %18 = icmp ult ptr %17, %7
  br i1 %18, label %.lr.ph, label %.loopexit, !llvm.loop !5

19:                                               ; preds = %.lr.ph
  %20 = ptrtoint ptr %.02630 to i64
  %21 = sub i64 %11, %20
  tail call void @partial_backward_merge8(ptr noundef %.02630, ptr noundef %1, i64 noundef %21, i64 noundef %.031, ptr noundef %5)
  br label %.loopexit

.loopexit:                                        ; preds = %16, %.preheader, %19
  %22 = icmp ult i64 %13, %3
  %23 = icmp ule i64 %13, %2
  %24 = and i1 %22, %23
  br i1 %24, label %.preheader, label %._crit_edge, !llvm.loop !7

._crit_edge:                                      ; preds = %.loopexit, %6
  ret void
}

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

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


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