; 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
declare dso_local void @partial_backward_merge8(ptr noundef, ptr noundef, i64 noundef, i64 noundef, ptr noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @blit_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
  %15 = alloca i32, align 4
  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
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = load i64, ptr %10, align 8, !tbaa !9
  %18 = getelementptr inbounds i8, ptr %16, i64 %17
  store ptr %18, ptr %14, align 8, !tbaa !5
  %19 = load i64, ptr %10, align 8, !tbaa !9
  %20 = load i64, ptr %11, align 8, !tbaa !9
  %21 = sub i64 %19, %20
  %22 = load i64, ptr %9, align 8, !tbaa !9
  %23 = icmp ule i64 %21, %22
  br i1 %23, label %24, label %30

24:                                               ; preds = %6
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  %27 = load i64, ptr %10, align 8, !tbaa !9
  %28 = load i64, ptr %11, align 8, !tbaa !9
  %29 = load ptr, ptr %12, align 8, !tbaa !5
  call void @partial_backward_merge8(ptr noundef %25, ptr noundef %26, i64 noundef %27, i64 noundef %28, ptr noundef %29)
  store i32 1, ptr %15, align 4
  br label %79

30:                                               ; preds = %6
  br label %31

31:                                               ; preds = %75, %30
  %32 = load i64, ptr %11, align 8, !tbaa !9
  %33 = load i64, ptr %10, align 8, !tbaa !9
  %34 = icmp ult i64 %32, %33
  br i1 %34, label %35, label %78

35:                                               ; preds = %31
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %36, ptr %13, align 8, !tbaa !5
  br label %37

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

43:                                               ; preds = %37
  %44 = load ptr, ptr %13, align 8, !tbaa !5
  %45 = load i64, ptr %11, align 8, !tbaa !9
  %46 = mul i64 %45, 2
  %47 = getelementptr inbounds i8, ptr %44, i64 %46
  %48 = load ptr, ptr %14, align 8, !tbaa !5
  %49 = icmp ult ptr %47, %48
  br i1 %49, label %50, label %57

50:                                               ; preds = %43
  %51 = load ptr, ptr %13, align 8, !tbaa !5
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  %53 = load i64, ptr %9, align 8, !tbaa !9
  %54 = load i64, ptr %11, align 8, !tbaa !9
  %55 = load i64, ptr %11, align 8, !tbaa !9
  %56 = load ptr, ptr %12, align 8, !tbaa !5
  call void @blit_merge_block8(ptr noundef %51, ptr noundef %52, i64 noundef %53, i64 noundef %54, i64 noundef %55, ptr noundef %56)
  br label %70

57:                                               ; preds = %43
  %58 = load ptr, ptr %13, align 8, !tbaa !5
  %59 = load ptr, ptr %8, align 8, !tbaa !5
  %60 = load i64, ptr %9, align 8, !tbaa !9
  %61 = load i64, ptr %11, align 8, !tbaa !9
  %62 = load ptr, ptr %14, align 8, !tbaa !5
  %63 = load ptr, ptr %13, align 8, !tbaa !5
  %64 = ptrtoint ptr %62 to i64
  %65 = ptrtoint ptr %63 to i64
  %66 = sub i64 %64, %65
  %67 = load i64, ptr %11, align 8, !tbaa !9
  %68 = sub i64 %66, %67
  %69 = load ptr, ptr %12, align 8, !tbaa !5
  call void @blit_merge_block8(ptr noundef %58, ptr noundef %59, i64 noundef %60, i64 noundef %61, i64 noundef %68, ptr noundef %69)
  br label %75

70:                                               ; preds = %50
  %71 = load i64, ptr %11, align 8, !tbaa !9
  %72 = mul i64 %71, 2
  %73 = load ptr, ptr %13, align 8, !tbaa !5
  %74 = getelementptr inbounds i8, ptr %73, i64 %72
  store ptr %74, ptr %13, align 8, !tbaa !5
  br label %37, !llvm.loop !11

75:                                               ; preds = %57, %37
  %76 = load i64, ptr %11, align 8, !tbaa !9
  %77 = mul i64 %76, 2
  store i64 %77, ptr %11, align 8, !tbaa !9
  br label %31, !llvm.loop !13

78:                                               ; preds = %31
  store i32 0, ptr %15, align 4
  br label %79

79:                                               ; preds = %78, %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #2
  %80 = load i32, ptr %15, align 4
  switch i32 %80, label %82 [
    i32 0, label %81
    i32 1, label %81
  ]

81:                                               ; preds = %79, %79
  ret void

82:                                               ; preds = %79
  unreachable
}

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
declare dso_local void @partial_backward_merge8(ptr noundef, ptr noundef, i64 noundef, i64 noundef, ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local void @blit_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 = sub i64 %3, %4
  %.not = icmp ugt i64 %8, %2
  br i1 %.not, label %.preheader39, label %11

.preheader39:                                     ; preds = %6
  %9 = icmp ult i64 %4, %3
  br i1 %9, label %.preheader.lr.ph, label %.loopexit40

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

11:                                               ; preds = %6
  tail call void @partial_backward_merge8(ptr noundef %0, ptr noundef %1, i64 noundef %3, i64 noundef %4, ptr noundef %5)
  br label %.loopexit40

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

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

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

19:                                               ; preds = %.lr.ph
  %20 = ptrtoint ptr %.03542 to i64
  %21 = add i64 %.043, %20
  %22 = sub i64 %10, %21
  tail call void @blit_merge_block8(ptr noundef %.03542, ptr noundef %1, i64 noundef %2, i64 noundef %.043, i64 noundef %22, ptr noundef %5)
  br label %.loopexit

.loopexit:                                        ; preds = %16, %.preheader, %19
  %23 = icmp ult i64 %13, %3
  br i1 %23, label %.preheader, label %.loopexit40, !llvm.loop !7

.loopexit40:                                      ; preds = %.loopexit, %.preheader39, %11
  ret void
}

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,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass