; LLVM IR from scandum/blitsort :: src (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 @tail_merge128(ptr noundef, ptr noundef, i64 noundef, i64 noundef, i64 noundef, ptr noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local i64 @quad_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
  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 x86_fp80, ptr %15, i64 %16
  store ptr %17, ptr %14, align 8, !tbaa !5
  %18 = load i64, ptr %11, align 8, !tbaa !9
  %19 = mul i64 %18, 4
  store i64 %19, ptr %11, align 8, !tbaa !9
  br label %20

20:                                               ; preds = %47, %6
  %21 = load i64, ptr %11, align 8, !tbaa !9
  %22 = load i64, ptr %10, align 8, !tbaa !9
  %23 = icmp ule i64 %21, %22
  br i1 %23, label %24, label %28

24:                                               ; preds = %20
  %25 = load i64, ptr %11, align 8, !tbaa !9
  %26 = load i64, ptr %9, align 8, !tbaa !9
  %27 = icmp ule i64 %25, %26
  br label %28

28:                                               ; preds = %24, %20
  %29 = phi i1 [ false, %20 ], [ %27, %24 ]
  br i1 %29, label %30, label %62

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

32:                                               ; preds = %41, %30
  %33 = load ptr, ptr %13, align 8, !tbaa !5
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = load i64, ptr %11, align 8, !tbaa !9
  %36 = udiv i64 %35, 4
  %37 = load ptr, ptr %12, align 8, !tbaa !5
  call void @quad_merge_block128(ptr noundef %33, ptr noundef %34, i64 noundef %36, ptr noundef %37)
  %38 = load i64, ptr %11, align 8, !tbaa !9
  %39 = load ptr, ptr %13, align 8, !tbaa !5
  %40 = getelementptr inbounds x86_fp80, ptr %39, i64 %38
  store ptr %40, ptr %13, align 8, !tbaa !5
  br label %41

41:                                               ; preds = %32
  %42 = load ptr, ptr %13, align 8, !tbaa !5
  %43 = load i64, ptr %11, align 8, !tbaa !9
  %44 = getelementptr inbounds x86_fp80, ptr %42, i64 %43
  %45 = load ptr, ptr %14, align 8, !tbaa !5
  %46 = icmp ule ptr %44, %45
  br i1 %46, label %32, label %47, !llvm.loop !11

47:                                               ; preds = %41
  %48 = load ptr, ptr %13, align 8, !tbaa !5
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = load i64, ptr %9, align 8, !tbaa !9
  %51 = load ptr, ptr %14, align 8, !tbaa !5
  %52 = load ptr, ptr %13, align 8, !tbaa !5
  %53 = ptrtoint ptr %51 to i64
  %54 = ptrtoint ptr %52 to i64
  %55 = sub i64 %53, %54
  %56 = sdiv exact i64 %55, 16
  %57 = load i64, ptr %11, align 8, !tbaa !9
  %58 = udiv i64 %57, 4
  %59 = load ptr, ptr %12, align 8, !tbaa !5
  call void @tail_merge128(ptr noundef %48, ptr noundef %49, i64 noundef %50, i64 noundef %56, i64 noundef %58, ptr noundef %59)
  %60 = load i64, ptr %11, align 8, !tbaa !9
  %61 = mul i64 %60, 4
  store i64 %61, ptr %11, align 8, !tbaa !9
  br label %20, !llvm.loop !13

62:                                               ; preds = %28
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  %64 = load ptr, ptr %8, align 8, !tbaa !5
  %65 = load i64, ptr %9, align 8, !tbaa !9
  %66 = load i64, ptr %10, align 8, !tbaa !9
  %67 = load i64, ptr %11, align 8, !tbaa !9
  %68 = udiv i64 %67, 4
  %69 = load ptr, ptr %12, align 8, !tbaa !5
  call void @tail_merge128(ptr noundef %63, ptr noundef %64, i64 noundef %65, i64 noundef %66, i64 noundef %68, ptr noundef %69)
  %70 = load i64, ptr %11, align 8, !tbaa !9
  %71 = udiv i64 %70, 2
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #2
  ret i64 %71
}

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 @tail_merge128(ptr noundef, ptr noundef, i64 noundef, i64 noundef, i64 noundef, ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local range(i64 0, -9223372036854775808) i64 @quad_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
  %invariant.umin = tail call i64 @llvm.umin.i64(i64 %3, i64 %2)
  %.035 = shl i64 %4, 2
  %.not39 = icmp ugt i64 %.035, %invariant.umin
  br i1 %.not39, label %._crit_edge, label %.preheader.lr.ph

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

.preheader:                                       ; preds = %.preheader.lr.ph, %13
  %.037 = phi i64 [ %.035, %.preheader.lr.ph ], [ %.0, %13 ]
  %.0.in36 = phi i64 [ %4, %.preheader.lr.ph ], [ %.037, %13 ]
  %9 = and i64 %.0.in36, 4611686018427387903
  br label %10

10:                                               ; preds = %.preheader, %10
  %.031 = phi ptr [ %11, %10 ], [ %0, %.preheader ]
  tail call void @quad_merge_block128(ptr noundef %.031, ptr noundef %1, i64 noundef %9, ptr noundef %5)
  %11 = getelementptr inbounds x86_fp80, ptr %.031, i64 %.037
  %12 = getelementptr inbounds x86_fp80, ptr %11, i64 %.037
  %.not = icmp ugt ptr %12, %7
  br i1 %.not, label %13, label %10, !llvm.loop !5

13:                                               ; preds = %10
  %14 = ptrtoint ptr %11 to i64
  %15 = sub i64 %8, %14
  %16 = ashr exact i64 %15, 4
  tail call void @tail_merge128(ptr noundef %11, ptr noundef %1, i64 noundef %2, i64 noundef %16, i64 noundef %9, ptr noundef %5)
  %.0 = shl i64 %.037, 2
  %.not40 = icmp ugt i64 %.0, %invariant.umin
  br i1 %.not40, label %._crit_edge, label %.preheader, !llvm.loop !7

._crit_edge:                                      ; preds = %13, %6
  %.0.in.lcssa = phi i64 [ %4, %6 ], [ %.037, %13 ]
  %.0.lcssa = phi i64 [ %.035, %6 ], [ %.0, %13 ]
  %17 = and i64 %.0.in.lcssa, 4611686018427387903
  tail call void @tail_merge128(ptr noundef %0, ptr noundef %1, i64 noundef %2, i64 noundef %3, i64 noundef %17, ptr noundef %5)
  %18 = lshr exact i64 %.0.lcssa, 1
  ret i64 %18
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umin.i64(i64, i64) #1

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" }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass