; 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: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #1

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #1

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

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

; Function Attrs: nounwind uwtable
declare dso_local i64 @quad_swap128(ptr noundef, i64 noundef, ptr noundef) #4

; Function Attrs: nounwind uwtable
declare dso_local i64 @quad_merge128(ptr noundef, ptr noundef, i64 noundef, i64 noundef, i64 noundef, ptr noundef) #4

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

; Function Attrs: nounwind uwtable
define dso_local void @quadsort128(ptr noundef %0, i64 noundef %1, ptr noundef %2) #4 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca [512 x x86_fp80], align 16
  %14 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %15, ptr %7, align 8, !tbaa !5
  %16 = load i64, ptr %5, align 8, !tbaa !9
  %17 = icmp ult i64 %16, 32
  br i1 %17, label %18, label %26

18:                                               ; preds = %3
  %19 = load i64, ptr %5, align 8, !tbaa !9
  %20 = call ptr @llvm.stacksave.p0()
  store ptr %20, ptr %8, align 8
  %21 = alloca x86_fp80, i64 %19, align 16
  store i64 %19, ptr %9, align 8
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = load i64, ptr %5, align 8, !tbaa !9
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  call void @tail_swap128(ptr noundef %22, ptr noundef %21, i64 noundef %23, ptr noundef %24)
  %25 = load ptr, ptr %8, align 8
  call void @llvm.stackrestore.p0(ptr %25)
  br label %82

26:                                               ; preds = %3
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = load i64, ptr %5, align 8, !tbaa !9
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = call i64 @quad_swap128(ptr noundef %27, i64 noundef %28, ptr noundef %29)
  %31 = icmp eq i64 %30, 0
  br i1 %31, label %32, label %81

32:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  store ptr null, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %33 = load i64, ptr %5, align 8, !tbaa !9
  store i64 %33, ptr %12, align 8, !tbaa !9
  %34 = load i64, ptr %5, align 8, !tbaa !9
  %35 = icmp ugt i64 %34, 4194304
  br i1 %35, label %36, label %47

36:                                               ; preds = %32
  store i64 4194304, ptr %12, align 8, !tbaa !9
  br label %37

37:                                               ; preds = %43, %36
  %38 = load i64, ptr %12, align 8, !tbaa !9
  %39 = mul i64 %38, 8
  %40 = load i64, ptr %5, align 8, !tbaa !9
  %41 = icmp ule i64 %39, %40
  br i1 %41, label %42, label %46

42:                                               ; preds = %37
  br label %43

43:                                               ; preds = %42
  %44 = load i64, ptr %12, align 8, !tbaa !9
  %45 = mul i64 %44, 4
  store i64 %45, ptr %12, align 8, !tbaa !9
  br label %37, !llvm.loop !11

46:                                               ; preds = %37
  br label %47

47:                                               ; preds = %46, %32
  %48 = load i64, ptr %12, align 8, !tbaa !9
  %49 = mul i64 %48, 16
  %50 = call noalias ptr @malloc(i64 noundef %49) #6
  store ptr %50, ptr %10, align 8, !tbaa !5
  %51 = load ptr, ptr %10, align 8, !tbaa !5
  %52 = icmp eq ptr %51, null
  br i1 %52, label %53, label %64

53:                                               ; preds = %47
  call void @llvm.lifetime.start.p0(i64 8192, ptr %13) #5
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  %55 = getelementptr inbounds [512 x x86_fp80], ptr %13, i64 0, i64 0
  %56 = load i64, ptr %5, align 8, !tbaa !9
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = call i64 @quad_merge128(ptr noundef %54, ptr noundef %55, i64 noundef 512, i64 noundef %56, i64 noundef 32, ptr noundef %57)
  store i64 %58, ptr %11, align 8, !tbaa !9
  %59 = load ptr, ptr %7, align 8, !tbaa !5
  %60 = getelementptr inbounds [512 x x86_fp80], ptr %13, i64 0, i64 0
  %61 = load i64, ptr %5, align 8, !tbaa !9
  %62 = load i64, ptr %11, align 8, !tbaa !9
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  call void @rotate_merge128(ptr noundef %59, ptr noundef %60, i64 noundef 512, i64 noundef %61, i64 noundef %62, ptr noundef %63)
  store i32 1, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 8192, ptr %13) #5
  br label %78

64:                                               ; preds = %47
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = load ptr, ptr %10, align 8, !tbaa !5
  %67 = load i64, ptr %12, align 8, !tbaa !9
  %68 = load i64, ptr %5, align 8, !tbaa !9
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = call i64 @quad_merge128(ptr noundef %65, ptr noundef %66, i64 noundef %67, i64 noundef %68, i64 noundef 32, ptr noundef %69)
  store i64 %70, ptr %11, align 8, !tbaa !9
  %71 = load ptr, ptr %7, align 8, !tbaa !5
  %72 = load ptr, ptr %10, align 8, !tbaa !5
  %73 = load i64, ptr %12, align 8, !tbaa !9
  %74 = load i64, ptr %5, align 8, !tbaa !9
  %75 = load i64, ptr %11, align 8, !tbaa !9
  %76 = load ptr, ptr %6, align 8, !tbaa !5
  call void @rotate_merge128(ptr noundef %71, ptr noundef %72, i64 noundef %73, i64 noundef %74, i64 noundef %75, ptr noundef %76)
  %77 = load ptr, ptr %10, align 8, !tbaa !5
  call void @free(ptr noundef %77) #5
  store i32 0, ptr %14, align 4
  br label %78

78:                                               ; preds = %64, %53
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  %79 = load i32, ptr %14, align 4
  switch i32 %79, label %83 [
    i32 0, label %80
  ]

80:                                               ; preds = %78
  br label %81

81:                                               ; preds = %80, %26
  br label %82

82:                                               ; preds = %81, %18
  store i32 0, ptr %14, align 4
  br label %83

83:                                               ; preds = %82, %78
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  %84 = load i32, ptr %14, align 4
  switch i32 %84, label %86 [
    i32 0, label %85
    i32 1, label %85
  ]

85:                                               ; preds = %83, %83
  ret void

86:                                               ; preds = %83
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind willreturn }
attributes #2 = { nounwind allocsize(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 #3 = { nounwind "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 #4 = { 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 #5 = { nounwind }
attributes #6 = { nounwind allocsize(0) }

!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"}


; 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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #1

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #3

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

; Function Attrs: nounwind uwtable
declare dso_local i64 @quad_swap128(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
declare dso_local i64 @quad_merge128(ptr noundef, ptr noundef, i64 noundef, i64 noundef, i64 noundef, ptr noundef) local_unnamed_addr #4

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

; Function Attrs: nounwind uwtable
define dso_local void @quadsort128(ptr noundef %0, i64 noundef %1, ptr noundef %2) local_unnamed_addr #4 {
  %4 = alloca [512 x x86_fp80], align 16
  %5 = icmp ult i64 %1, 32
  br i1 %5, label %6, label %9

6:                                                ; preds = %3
  %7 = tail call ptr @llvm.stacksave.p0()
  %8 = alloca x86_fp80, i64 %1, align 16
  call void @tail_swap128(ptr noundef %0, ptr noundef nonnull %8, i64 noundef %1, ptr noundef %2)
  call void @llvm.stackrestore.p0(ptr %7)
  br label %22

9:                                                ; preds = %3
  %10 = tail call i64 @quad_swap128(ptr noundef %0, i64 noundef %1, ptr noundef %2)
  %11 = icmp eq i64 %10, 0
  br i1 %11, label %12, label %22

12:                                               ; preds = %9
  %13 = icmp ugt i64 %1, 4194304
  br i1 %13, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %12, %.preheader
  %.036 = phi i64 [ %15, %.preheader ], [ 4194304, %12 ]
  %14 = shl i64 %.036, 3
  %.not = icmp ugt i64 %14, %1
  %15 = shl i64 %.036, 2
  br i1 %.not, label %.loopexit, label %.preheader, !llvm.loop !5

.loopexit:                                        ; preds = %.preheader, %12
  %.1 = phi i64 [ %1, %12 ], [ %.036, %.preheader ]
  %16 = shl i64 %.1, 4
  %17 = tail call noalias ptr @malloc(i64 noundef %16) #5
  %.not40 = icmp eq ptr %17, null
  br i1 %.not40, label %18, label %20

18:                                               ; preds = %.loopexit
  call void @llvm.lifetime.start.p0(i64 8192, ptr nonnull %4) #6
  %19 = call i64 @quad_merge128(ptr noundef %0, ptr noundef nonnull %4, i64 noundef 512, i64 noundef %1, i64 noundef 32, ptr noundef %2)
  call void @rotate_merge128(ptr noundef %0, ptr noundef nonnull %4, i64 noundef 512, i64 noundef %1, i64 noundef %19, ptr noundef %2)
  call void @llvm.lifetime.end.p0(i64 8192, ptr nonnull %4) #6
  br label %22

20:                                               ; preds = %.loopexit
  %21 = tail call i64 @quad_merge128(ptr noundef %0, ptr noundef nonnull %17, i64 noundef %.1, i64 noundef %1, i64 noundef 32, ptr noundef %2)
  tail call void @rotate_merge128(ptr noundef %0, ptr noundef nonnull %17, i64 noundef %.1, i64 noundef %1, i64 noundef %21, ptr noundef %2)
  tail call void @free(ptr noundef nonnull %17) #6
  br label %22

22:                                               ; preds = %18, %20, %6, %9
  ret void
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn }
attributes #2 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 #3 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 #4 = { 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 #5 = { nounwind allocsize(0) }
attributes #6 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


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