; LLVM IR from clibraries/array-algorithms :: test (tests)

; 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"

@.str.1 = external hidden unnamed_addr constant [74 x i8], align 1
@.str.102 = external hidden unnamed_addr constant [13 x i8], align 1
@__PRETTY_FUNCTION__.test_partial_sort = external hidden unnamed_addr constant [25 x i8], align 1

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

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

; 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 hidden i32 @compare_int(ptr noundef, ptr noundef, ptr noundef) #2

declare void @intv_random_shuffle(ptr noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local void @test_partial_sort() #2 {
  %1 = alloca [100 x i32], align 16
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 400, ptr %1) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %6

6:                                                ; preds = %15, %0
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = icmp slt i32 %7, 100
  br i1 %8, label %10, label %9

9:                                                ; preds = %6
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %18

10:                                               ; preds = %6
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [100 x i32], ptr %1, i64 0, i64 %13
  store i32 %11, ptr %14, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %10
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = add nsw i32 %16, 1
  store i32 %17, ptr %2, align 4, !tbaa !5
  br label %6, !llvm.loop !9

18:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %50, %18
  %20 = load i32, ptr %3, align 4, !tbaa !5
  %21 = icmp slt i32 %20, 1000
  br i1 %21, label %23, label %22

22:                                               ; preds = %19
  store i32 5, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %53

23:                                               ; preds = %19
  %24 = getelementptr inbounds [100 x i32], ptr %1, i64 0, i64 0
  %25 = getelementptr inbounds [100 x i32], ptr %1, i64 0, i64 0
  %26 = getelementptr inbounds i32, ptr %25, i64 100
  call void @intv_random_shuffle(ptr noundef %24, ptr noundef %26)
  %27 = getelementptr inbounds [100 x i32], ptr %1, i64 0, i64 0
  %28 = getelementptr inbounds [100 x i32], ptr %1, i64 0, i64 0
  %29 = getelementptr inbounds i32, ptr %28, i64 10
  %30 = getelementptr inbounds [100 x i32], ptr %1, i64 0, i64 0
  %31 = getelementptr inbounds i32, ptr %30, i64 100
  call void @intv_partial_sort(ptr noundef %27, ptr noundef %29, ptr noundef %31, ptr noundef @compare_int, ptr noundef null)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %32

32:                                               ; preds = %46, %23
  %33 = load i32, ptr %5, align 4, !tbaa !5
  %34 = icmp slt i32 %33, 10
  br i1 %34, label %36, label %35

35:                                               ; preds = %32
  store i32 8, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %49

36:                                               ; preds = %32
  %37 = load i32, ptr %5, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [100 x i32], ptr %1, i64 0, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = load i32, ptr %5, align 4, !tbaa !5
  %42 = icmp eq i32 %40, %41
  br i1 %42, label %43, label %44

43:                                               ; preds = %36
  br label %45

44:                                               ; preds = %36
  call void @__assert_fail(ptr noundef @.str.102, ptr noundef @.str.1, i32 noundef 606, ptr noundef @__PRETTY_FUNCTION__.test_partial_sort) #5
  unreachable

45:                                               ; preds = %43
  br label %46

46:                                               ; preds = %45
  %47 = load i32, ptr %5, align 4, !tbaa !5
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %5, align 4, !tbaa !5
  br label %32, !llvm.loop !11

49:                                               ; preds = %35
  br label %50

50:                                               ; preds = %49
  %51 = load i32, ptr %3, align 4, !tbaa !5
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr %3, align 4, !tbaa !5
  br label %19, !llvm.loop !12

53:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 400, ptr %1) #4
  ret void
}

declare void @intv_partial_sort(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noreturn 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 #2 = { 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 #3 = { "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 }
attributes #5 = { noreturn 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


; 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"

@.str.1 = external hidden unnamed_addr constant [74 x i8], align 1
@.str.102 = external hidden unnamed_addr constant [13 x i8], align 1
@__PRETTY_FUNCTION__.test_partial_sort = external hidden unnamed_addr constant [25 x i8], align 1

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

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
declare hidden i32 @compare_int(ptr noundef, ptr noundef, ptr noundef) #2

declare void @intv_random_shuffle(ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local void @test_partial_sort() local_unnamed_addr #2 {
vector.ph:
  %0 = alloca [100 x i32], align 16
  call void @llvm.lifetime.start.p0(i64 400, ptr nonnull %0) #4
  %1 = getelementptr inbounds i8, ptr %0, i64 16
  store <4 x i32> <i32 0, i32 1, i32 2, i32 3>, ptr %0, align 16, !tbaa !5
  store <4 x i32> <i32 4, i32 5, i32 6, i32 7>, ptr %1, align 16, !tbaa !5
  %2 = getelementptr inbounds i8, ptr %0, i64 32
  %3 = getelementptr inbounds i8, ptr %0, i64 48
  store <4 x i32> <i32 8, i32 9, i32 10, i32 11>, ptr %2, align 16, !tbaa !5
  store <4 x i32> <i32 12, i32 13, i32 14, i32 15>, ptr %3, align 16, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 64
  %5 = getelementptr inbounds i8, ptr %0, i64 80
  store <4 x i32> <i32 16, i32 17, i32 18, i32 19>, ptr %4, align 16, !tbaa !5
  store <4 x i32> <i32 20, i32 21, i32 22, i32 23>, ptr %5, align 16, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 96
  %7 = getelementptr inbounds i8, ptr %0, i64 112
  store <4 x i32> <i32 24, i32 25, i32 26, i32 27>, ptr %6, align 16, !tbaa !5
  store <4 x i32> <i32 28, i32 29, i32 30, i32 31>, ptr %7, align 16, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 128
  %9 = getelementptr inbounds i8, ptr %0, i64 144
  store <4 x i32> <i32 32, i32 33, i32 34, i32 35>, ptr %8, align 16, !tbaa !5
  store <4 x i32> <i32 36, i32 37, i32 38, i32 39>, ptr %9, align 16, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %0, i64 160
  %11 = getelementptr inbounds i8, ptr %0, i64 176
  store <4 x i32> <i32 40, i32 41, i32 42, i32 43>, ptr %10, align 16, !tbaa !5
  store <4 x i32> <i32 44, i32 45, i32 46, i32 47>, ptr %11, align 16, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %0, i64 192
  %13 = getelementptr inbounds i8, ptr %0, i64 208
  store <4 x i32> <i32 48, i32 49, i32 50, i32 51>, ptr %12, align 16, !tbaa !5
  store <4 x i32> <i32 52, i32 53, i32 54, i32 55>, ptr %13, align 16, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %0, i64 224
  %15 = getelementptr inbounds i8, ptr %0, i64 240
  store <4 x i32> <i32 56, i32 57, i32 58, i32 59>, ptr %14, align 16, !tbaa !5
  store <4 x i32> <i32 60, i32 61, i32 62, i32 63>, ptr %15, align 16, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %0, i64 256
  %17 = getelementptr inbounds i8, ptr %0, i64 272
  store <4 x i32> <i32 64, i32 65, i32 66, i32 67>, ptr %16, align 16, !tbaa !5
  store <4 x i32> <i32 68, i32 69, i32 70, i32 71>, ptr %17, align 16, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %0, i64 288
  %19 = getelementptr inbounds i8, ptr %0, i64 304
  store <4 x i32> <i32 72, i32 73, i32 74, i32 75>, ptr %18, align 16, !tbaa !5
  store <4 x i32> <i32 76, i32 77, i32 78, i32 79>, ptr %19, align 16, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %0, i64 320
  %21 = getelementptr inbounds i8, ptr %0, i64 336
  store <4 x i32> <i32 80, i32 81, i32 82, i32 83>, ptr %20, align 16, !tbaa !5
  store <4 x i32> <i32 84, i32 85, i32 86, i32 87>, ptr %21, align 16, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %0, i64 352
  %23 = getelementptr inbounds i8, ptr %0, i64 368
  store <4 x i32> <i32 88, i32 89, i32 90, i32 91>, ptr %22, align 16, !tbaa !5
  store <4 x i32> <i32 92, i32 93, i32 94, i32 95>, ptr %23, align 16, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %0, i64 384
  store i32 96, ptr %24, align 16, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %0, i64 388
  store i32 97, ptr %25, align 4, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %0, i64 392
  store i32 98, ptr %26, align 8, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %0, i64 396
  store i32 99, ptr %27, align 4, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %0, i64 400
  %29 = getelementptr inbounds i8, ptr %0, i64 40
  %30 = getelementptr inbounds i8, ptr %0, i64 32
  %31 = getelementptr inbounds i8, ptr %0, i64 36
  br label %33

32:                                               ; preds = %42
  call void @llvm.lifetime.end.p0(i64 400, ptr nonnull %0) #4
  ret void

33:                                               ; preds = %vector.ph, %42
  %.01014 = phi i32 [ 0, %vector.ph ], [ %43, %42 ]
  call void @intv_random_shuffle(ptr noundef nonnull %0, ptr noundef nonnull %28) #4
  call void @intv_partial_sort(ptr noundef nonnull %0, ptr noundef nonnull %29, ptr noundef nonnull %28, ptr noundef nonnull @compare_int, ptr noundef null) #4
  %34 = load <8 x i32>, ptr %0, align 16
  %.fr = freeze <8 x i32> %34
  %35 = load i32, ptr %30, align 16
  %.fr41 = freeze i32 %35
  %36 = icmp eq i32 %.fr41, 8
  %37 = load i32, ptr %31, align 4
  %38 = icmp eq i32 %37, 9
  %39 = icmp ne <8 x i32> %.fr, <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>
  %40 = bitcast <8 x i1> %39 to i8
  %41 = icmp eq i8 %40, 0
  %op.rdx = and i1 %41, %36
  %op.rdx39 = select i1 %op.rdx, i1 %38, i1 false
  br i1 %op.rdx39, label %42, label %44

42:                                               ; preds = %33
  %43 = add nuw nsw i32 %.01014, 1
  %exitcond20.not = icmp eq i32 %43, 1000
  br i1 %exitcond20.not, label %32, label %33, !llvm.loop !9

44:                                               ; preds = %33
  call void @__assert_fail(ptr noundef nonnull @.str.102, ptr noundef nonnull @.str.1, i32 noundef 606, ptr noundef nonnull @__PRETTY_FUNCTION__.test_partial_sort) #5
  unreachable
}

declare void @intv_partial_sort(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noreturn 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 #2 = { 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 #3 = { "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 }
attributes #5 = { noreturn 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalDCEPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopInstSimplifyPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass