; 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_merge128(ptr noundef, ptr noundef, i64 noundef, i64 noundef, ptr noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @blit_merge128(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 x86_fp80, 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_merge128(ptr noundef %25, ptr noundef %26, i64 noundef %27, i64 noundef %28, ptr noundef %29)
  store i32 1, ptr %15, align 4
  br label %80

30:                                               ; preds = %6
  br label %31

31:                                               ; preds = %76, %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 %79

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 = %71, %35
  %38 = load ptr, ptr %13, align 8, !tbaa !5
  %39 = load i64, ptr %11, align 8, !tbaa !9
  %40 = getelementptr inbounds x86_fp80, 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 %76

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 x86_fp80, 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_block128(ptr noundef %51, ptr noundef %52, i64 noundef %53, i64 noundef %54, i64 noundef %55, ptr noundef %56)
  br label %71

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 = sdiv exact i64 %66, 16
  %68 = load i64, ptr %11, align 8, !tbaa !9
  %69 = sub i64 %67, %68
  %70 = load ptr, ptr %12, align 8, !tbaa !5
  call void @blit_merge_block128(ptr noundef %58, ptr noundef %59, i64 noundef %60, i64 noundef %61, i64 noundef %69, ptr noundef %70)
  br label %76

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

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

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

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

82:                                               ; preds = %80, %80
  ret void

83:                                               ; preds = %80
  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_merge128(ptr noundef, ptr noundef, i64 noundef, i64 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @blit_merge_block128(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_merge128(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 x86_fp80, ptr %0, i64 %3
  %8 = sub i64 %3, %4
  %.not = icmp ugt i64 %8, %2
  br i1 %.not, label %.preheader38, label %11

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

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

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

.preheader:                                       ; preds = %.preheader.lr.ph, %.loopexit
  %.042 = phi i64 [ %4, %.preheader.lr.ph ], [ %24, %.loopexit ]
  %12 = icmp slt i64 %.042, %3
  br i1 %12, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader
  %.idx = shl i64 %.042, 5
  br label %13

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

16:                                               ; preds = %13
  tail call void @blit_merge_block128(ptr noundef %.03541, ptr noundef %1, i64 noundef %2, i64 noundef %.042, i64 noundef %.042, ptr noundef %5)
  %17 = getelementptr inbounds x86_fp80, ptr %14, i64 %.042
  %18 = icmp ult ptr %17, %7
  br i1 %18, label %13, label %.loopexit, !llvm.loop !5

19:                                               ; preds = %13
  %20 = ptrtoint ptr %.03541 to i64
  %21 = sub i64 %10, %20
  %22 = ashr exact i64 %21, 4
  %23 = sub i64 %22, %.042
  tail call void @blit_merge_block128(ptr noundef %.03541, ptr noundef %1, i64 noundef %2, i64 noundef %.042, i64 noundef %23, ptr noundef %5)
  br label %.loopexit

.loopexit:                                        ; preds = %16, %.preheader, %19
  %24 = shl i64 %.042, 1
  %25 = icmp ult i64 %24, %3
  br i1 %25, label %.preheader, label %.loopexit39, !llvm.loop !7

.loopexit39:                                      ; preds = %.loopexit, %.preheader38, %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,SROAPass,SimplifyCFGPass,TailCallElimPass