; 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.101 = external hidden unnamed_addr constant [21 x i8], align 1
@__PRETTY_FUNCTION__.test_nth_element = external hidden unnamed_addr constant [24 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

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

; Function Attrs: nounwind uwtable
define dso_local void @test_nth_element() #2 {
  %1 = alloca [32 x i32], align 16
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 128, 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 %4

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

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

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

13:                                               ; preds = %8
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = add nsw i32 %14, 1
  store i32 %15, ptr %2, align 4, !tbaa !5
  br label %4, !llvm.loop !9

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

17:                                               ; preds = %37, %16
  %18 = load i32, ptr %3, align 4, !tbaa !5
  %19 = icmp slt i32 %18, 10
  br i1 %19, label %21, label %20

20:                                               ; preds = %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %40

21:                                               ; preds = %17
  %22 = getelementptr inbounds [32 x i32], ptr %1, i64 0, i64 0
  %23 = getelementptr inbounds [32 x i32], ptr %1, i64 0, i64 0
  %24 = getelementptr inbounds i32, ptr %23, i64 32
  call void @intv_random_shuffle(ptr noundef %22, ptr noundef %24)
  %25 = getelementptr inbounds [32 x i32], ptr %1, i64 0, i64 0
  %26 = getelementptr inbounds [32 x i32], ptr %1, i64 0, i64 0
  %27 = getelementptr inbounds i32, ptr %26, i64 16
  %28 = getelementptr inbounds [32 x i32], ptr %1, i64 0, i64 0
  %29 = getelementptr inbounds i32, ptr %28, i64 32
  call void @intv_nth_element(ptr noundef %25, ptr noundef %27, ptr noundef %29, ptr noundef @compare_int, ptr noundef null)
  %30 = getelementptr inbounds [32 x i32], ptr %1, i64 0, i64 0
  call void @print_array(ptr noundef %30, i32 noundef 32)
  %31 = getelementptr inbounds [32 x i32], ptr %1, i64 0, i64 16
  %32 = load i32, ptr %31, align 16, !tbaa !5
  %33 = icmp eq i32 %32, 16
  br i1 %33, label %34, label %35

34:                                               ; preds = %21
  br label %36

35:                                               ; preds = %21
  call void @__assert_fail(ptr noundef @.str.101, ptr noundef @.str.1, i32 noundef 590, ptr noundef @__PRETTY_FUNCTION__.test_nth_element) #5
  unreachable

36:                                               ; preds = %34
  br label %37

37:                                               ; preds = %36
  %38 = load i32, ptr %3, align 4, !tbaa !5
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %3, align 4, !tbaa !5
  br label %17, !llvm.loop !11

40:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 128, ptr %1) #4
  ret void
}

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

declare void @intv_nth_element(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}


; 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.101 = external hidden unnamed_addr constant [21 x i8], align 1
@__PRETTY_FUNCTION__.test_nth_element = external hidden unnamed_addr constant [24 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

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

; Function Attrs: nounwind uwtable
define dso_local void @test_nth_element() local_unnamed_addr #2 {
.preheader:
  %0 = alloca [32 x i32], align 16
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %0) #4
  store <4 x i32> <i32 0, i32 1, i32 2, i32 3>, ptr %0, align 16, !tbaa !5
  %1 = getelementptr inbounds i8, ptr %0, i64 16
  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
  store <4 x i32> <i32 8, i32 9, i32 10, i32 11>, ptr %2, align 16, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 48
  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
  store <4 x i32> <i32 16, i32 17, i32 18, i32 19>, ptr %4, align 16, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 80
  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
  store <4 x i32> <i32 24, i32 25, i32 26, i32 27>, ptr %6, align 16, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 112
  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
  call void @intv_random_shuffle(ptr noundef nonnull %0, ptr noundef nonnull %8) #4
  call void @intv_nth_element(ptr noundef nonnull %0, ptr noundef nonnull %4, ptr noundef nonnull %8, ptr noundef nonnull @compare_int, ptr noundef null) #4
  call void @print_array(ptr noundef nonnull %0, i32 noundef 32)
  %9 = load i32, ptr %4, align 16, !tbaa !5
  %10 = icmp eq i32 %9, 16
  br i1 %10, label %11, label %39

11:                                               ; preds = %.preheader
  call void @intv_random_shuffle(ptr noundef nonnull %0, ptr noundef nonnull %8) #4
  call void @intv_nth_element(ptr noundef nonnull %0, ptr noundef nonnull %4, ptr noundef nonnull %8, ptr noundef nonnull @compare_int, ptr noundef null) #4
  call void @print_array(ptr noundef nonnull %0, i32 noundef 32)
  %12 = load i32, ptr %4, align 16, !tbaa !5
  %13 = icmp eq i32 %12, 16
  br i1 %13, label %14, label %39

14:                                               ; preds = %11
  call void @intv_random_shuffle(ptr noundef nonnull %0, ptr noundef nonnull %8) #4
  call void @intv_nth_element(ptr noundef nonnull %0, ptr noundef nonnull %4, ptr noundef nonnull %8, ptr noundef nonnull @compare_int, ptr noundef null) #4
  call void @print_array(ptr noundef nonnull %0, i32 noundef 32)
  %15 = load i32, ptr %4, align 16, !tbaa !5
  %16 = icmp eq i32 %15, 16
  br i1 %16, label %17, label %39

17:                                               ; preds = %14
  call void @intv_random_shuffle(ptr noundef nonnull %0, ptr noundef nonnull %8) #4
  call void @intv_nth_element(ptr noundef nonnull %0, ptr noundef nonnull %4, ptr noundef nonnull %8, ptr noundef nonnull @compare_int, ptr noundef null) #4
  call void @print_array(ptr noundef nonnull %0, i32 noundef 32)
  %18 = load i32, ptr %4, align 16, !tbaa !5
  %19 = icmp eq i32 %18, 16
  br i1 %19, label %20, label %39

20:                                               ; preds = %17
  call void @intv_random_shuffle(ptr noundef nonnull %0, ptr noundef nonnull %8) #4
  call void @intv_nth_element(ptr noundef nonnull %0, ptr noundef nonnull %4, ptr noundef nonnull %8, ptr noundef nonnull @compare_int, ptr noundef null) #4
  call void @print_array(ptr noundef nonnull %0, i32 noundef 32)
  %21 = load i32, ptr %4, align 16, !tbaa !5
  %22 = icmp eq i32 %21, 16
  br i1 %22, label %23, label %39

23:                                               ; preds = %20
  call void @intv_random_shuffle(ptr noundef nonnull %0, ptr noundef nonnull %8) #4
  call void @intv_nth_element(ptr noundef nonnull %0, ptr noundef nonnull %4, ptr noundef nonnull %8, ptr noundef nonnull @compare_int, ptr noundef null) #4
  call void @print_array(ptr noundef nonnull %0, i32 noundef 32)
  %24 = load i32, ptr %4, align 16, !tbaa !5
  %25 = icmp eq i32 %24, 16
  br i1 %25, label %26, label %39

26:                                               ; preds = %23
  call void @intv_random_shuffle(ptr noundef nonnull %0, ptr noundef nonnull %8) #4
  call void @intv_nth_element(ptr noundef nonnull %0, ptr noundef nonnull %4, ptr noundef nonnull %8, ptr noundef nonnull @compare_int, ptr noundef null) #4
  call void @print_array(ptr noundef nonnull %0, i32 noundef 32)
  %27 = load i32, ptr %4, align 16, !tbaa !5
  %28 = icmp eq i32 %27, 16
  br i1 %28, label %29, label %39

29:                                               ; preds = %26
  call void @intv_random_shuffle(ptr noundef nonnull %0, ptr noundef nonnull %8) #4
  call void @intv_nth_element(ptr noundef nonnull %0, ptr noundef nonnull %4, ptr noundef nonnull %8, ptr noundef nonnull @compare_int, ptr noundef null) #4
  call void @print_array(ptr noundef nonnull %0, i32 noundef 32)
  %30 = load i32, ptr %4, align 16, !tbaa !5
  %31 = icmp eq i32 %30, 16
  br i1 %31, label %32, label %39

32:                                               ; preds = %29
  call void @intv_random_shuffle(ptr noundef nonnull %0, ptr noundef nonnull %8) #4
  call void @intv_nth_element(ptr noundef nonnull %0, ptr noundef nonnull %4, ptr noundef nonnull %8, ptr noundef nonnull @compare_int, ptr noundef null) #4
  call void @print_array(ptr noundef nonnull %0, i32 noundef 32)
  %33 = load i32, ptr %4, align 16, !tbaa !5
  %34 = icmp eq i32 %33, 16
  br i1 %34, label %35, label %39

35:                                               ; preds = %32
  call void @intv_random_shuffle(ptr noundef nonnull %0, ptr noundef nonnull %8) #4
  call void @intv_nth_element(ptr noundef nonnull %0, ptr noundef nonnull %4, ptr noundef nonnull %8, ptr noundef nonnull @compare_int, ptr noundef null) #4
  call void @print_array(ptr noundef nonnull %0, i32 noundef 32)
  %36 = load i32, ptr %4, align 16, !tbaa !5
  %37 = icmp eq i32 %36, 16
  br i1 %37, label %38, label %39

38:                                               ; preds = %35
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %0) #4
  ret void

39:                                               ; preds = %35, %32, %29, %26, %23, %20, %17, %14, %11, %.preheader
  call void @__assert_fail(ptr noundef nonnull @.str.101, ptr noundef nonnull @.str.1, i32 noundef 590, ptr noundef nonnull @__PRETTY_FUNCTION__.test_nth_element) #5
  unreachable
}

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

declare void @intv_nth_element(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"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,LoopSimplifyPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass