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

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

%struct.Person = type { i32, [32 x i8] }

; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: nounwind uwtable
declare dso_local void @person_array_push_heap(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @person_array_pop_heap(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @person_array_sort_heap(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local ptr @person_array_partial_sort_copy(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5) #2 {
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, 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 %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store ptr %2, ptr %10, align 8, !tbaa !5
  store ptr %3, ptr %11, align 8, !tbaa !5
  store ptr %4, ptr %12, align 8, !tbaa !5
  store ptr %5, ptr %13, align 8, !tbaa !5
  %16 = load ptr, ptr %8, align 8, !tbaa !5
  %17 = load ptr, ptr %9, align 8, !tbaa !5
  %18 = icmp eq ptr %16, %17
  br i1 %18, label %23, label %19

19:                                               ; preds = %6
  %20 = load ptr, ptr %10, align 8, !tbaa !5
  %21 = load ptr, ptr %11, align 8, !tbaa !5
  %22 = icmp eq ptr %20, %21
  br i1 %22, label %23, label %25

23:                                               ; preds = %19, %6
  %24 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %24, ptr %7, align 8
  br label %92

25:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %26 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %26, ptr %14, align 8, !tbaa !5
  %27 = load ptr, ptr %14, align 8, !tbaa !5
  %28 = load ptr, ptr %8, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %27, ptr align 4 %28, i64 36, i1 false), !tbaa.struct !9
  %29 = load ptr, ptr %14, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.Person, ptr %29, i32 1
  store ptr %30, ptr %14, align 8, !tbaa !5
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.Person, ptr %31, i32 1
  store ptr %32, ptr %8, align 8, !tbaa !5
  br label %33

33:                                               ; preds = %47, %25
  %34 = load ptr, ptr %14, align 8, !tbaa !5
  %35 = load ptr, ptr %11, align 8, !tbaa !5
  %36 = icmp ne ptr %34, %35
  br i1 %36, label %37, label %58

37:                                               ; preds = %33
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = load ptr, ptr %9, align 8, !tbaa !5
  %40 = icmp eq ptr %38, %39
  br i1 %40, label %41, label %47

41:                                               ; preds = %37
  %42 = load ptr, ptr %10, align 8, !tbaa !5
  %43 = load ptr, ptr %14, align 8, !tbaa !5
  %44 = load ptr, ptr %12, align 8, !tbaa !5
  %45 = load ptr, ptr %13, align 8, !tbaa !5
  call void @person_array_sort_heap(ptr noundef %42, ptr noundef %43, ptr noundef %44, ptr noundef %45)
  %46 = load ptr, ptr %14, align 8, !tbaa !5
  store ptr %46, ptr %7, align 8
  store i32 1, ptr %15, align 4
  br label %91

47:                                               ; preds = %37
  %48 = load ptr, ptr %14, align 8, !tbaa !5
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %48, ptr align 4 %49, i64 36, i1 false), !tbaa.struct !9
  %50 = load ptr, ptr %8, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.Person, ptr %50, i32 1
  store ptr %51, ptr %8, align 8, !tbaa !5
  %52 = load ptr, ptr %14, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.Person, ptr %52, i32 1
  store ptr %53, ptr %14, align 8, !tbaa !5
  %54 = load ptr, ptr %10, align 8, !tbaa !5
  %55 = load ptr, ptr %14, align 8, !tbaa !5
  %56 = load ptr, ptr %12, align 8, !tbaa !5
  %57 = load ptr, ptr %13, align 8, !tbaa !5
  call void @person_array_push_heap(ptr noundef %54, ptr noundef %55, ptr noundef %56, ptr noundef %57)
  br label %33, !llvm.loop !13

58:                                               ; preds = %33
  br label %59

59:                                               ; preds = %82, %58
  %60 = load ptr, ptr %8, align 8, !tbaa !5
  %61 = load ptr, ptr %9, align 8, !tbaa !5
  %62 = icmp ne ptr %60, %61
  br i1 %62, label %63, label %85

63:                                               ; preds = %59
  %64 = load ptr, ptr %12, align 8, !tbaa !5
  %65 = load ptr, ptr %8, align 8, !tbaa !5
  %66 = load ptr, ptr %10, align 8, !tbaa !5
  %67 = load ptr, ptr %13, align 8, !tbaa !5
  %68 = call i32 %64(ptr noundef %65, ptr noundef %66, ptr noundef %67)
  %69 = icmp slt i32 %68, 0
  br i1 %69, label %70, label %82

70:                                               ; preds = %63
  %71 = load ptr, ptr %10, align 8, !tbaa !5
  %72 = load ptr, ptr %14, align 8, !tbaa !5
  %73 = load ptr, ptr %12, align 8, !tbaa !5
  %74 = load ptr, ptr %13, align 8, !tbaa !5
  call void @person_array_pop_heap(ptr noundef %71, ptr noundef %72, ptr noundef %73, ptr noundef %74)
  %75 = load ptr, ptr %14, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.Person, ptr %75, i64 -1
  %77 = load ptr, ptr %8, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %76, ptr align 4 %77, i64 36, i1 false), !tbaa.struct !9
  %78 = load ptr, ptr %10, align 8, !tbaa !5
  %79 = load ptr, ptr %14, align 8, !tbaa !5
  %80 = load ptr, ptr %12, align 8, !tbaa !5
  %81 = load ptr, ptr %13, align 8, !tbaa !5
  call void @person_array_push_heap(ptr noundef %78, ptr noundef %79, ptr noundef %80, ptr noundef %81)
  br label %82

82:                                               ; preds = %70, %63
  %83 = load ptr, ptr %8, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.Person, ptr %83, i32 1
  store ptr %84, ptr %8, align 8, !tbaa !5
  br label %59, !llvm.loop !15

85:                                               ; preds = %59
  %86 = load ptr, ptr %10, align 8, !tbaa !5
  %87 = load ptr, ptr %14, align 8, !tbaa !5
  %88 = load ptr, ptr %12, align 8, !tbaa !5
  %89 = load ptr, ptr %13, align 8, !tbaa !5
  call void @person_array_sort_heap(ptr noundef %86, ptr noundef %87, ptr noundef %88, ptr noundef %89)
  %90 = load ptr, ptr %14, align 8, !tbaa !5
  store ptr %90, ptr %7, align 8
  store i32 1, ptr %15, align 4
  br label %91

91:                                               ; preds = %85, %41
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  br label %92

92:                                               ; preds = %91, %23
  %93 = load ptr, ptr %7, align 8
  ret ptr %93
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{i64 0, i64 4, !10, i64 4, i64 32, !12}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!7, !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

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

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

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

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @person_array_partial_sort_copy(ptr noundef %0, ptr noundef readnone %1, ptr noundef %2, ptr noundef readnone %3, ptr noundef %4, ptr noundef %5) local_unnamed_addr #1 {
  %7 = icmp eq ptr %0, %1
  %8 = icmp eq ptr %2, %3
  %or.cond = or i1 %7, %8
  br i1 %or.cond, label %21, label %9

9:                                                ; preds = %6
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(36) %2, ptr noundef nonnull align 4 dereferenceable(36) %0, i64 36, i1 false), !tbaa.struct !5
  %10 = getelementptr inbounds i8, ptr %2, i64 36
  %.05160 = getelementptr inbounds i8, ptr %0, i64 36
  %.not61 = icmp eq ptr %10, %3
  br i1 %.not61, label %.preheader, label %.lr.ph

.preheader:                                       ; preds = %13, %9
  %.0.lcssa = phi ptr [ %10, %9 ], [ %14, %13 ]
  %.051.lcssa = phi ptr [ %.05160, %9 ], [ %.051, %13 ]
  %.not5765 = icmp eq ptr %.051.lcssa, %1
  br i1 %.not5765, label %.sink.split, label %.lr.ph67

.lr.ph67:                                         ; preds = %.preheader
  %11 = getelementptr inbounds i8, ptr %.0.lcssa, i64 -36
  br label %15

.lr.ph:                                           ; preds = %9, %13
  %.05163 = phi ptr [ %.051, %13 ], [ %.05160, %9 ]
  %.062 = phi ptr [ %14, %13 ], [ %10, %9 ]
  %12 = icmp eq ptr %.05163, %1
  br i1 %12, label %.sink.split, label %13

13:                                               ; preds = %.lr.ph
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(36) %.062, ptr noundef nonnull align 4 dereferenceable(36) %.05163, i64 36, i1 false), !tbaa.struct !5
  %14 = getelementptr inbounds i8, ptr %.062, i64 36
  tail call void @person_array_push_heap(ptr noundef %2, ptr noundef nonnull %14, ptr noundef %4, ptr noundef %5)
  %.051 = getelementptr inbounds i8, ptr %.05163, i64 36
  %.not = icmp eq ptr %14, %3
  br i1 %.not, label %.preheader, label %.lr.ph, !llvm.loop !11

15:                                               ; preds = %.lr.ph67, %19
  %.15266 = phi ptr [ %.051.lcssa, %.lr.ph67 ], [ %20, %19 ]
  %16 = tail call i32 %4(ptr noundef nonnull %.15266, ptr noundef %2, ptr noundef %5) #2
  %17 = icmp slt i32 %16, 0
  br i1 %17, label %18, label %19

18:                                               ; preds = %15
  tail call void @person_array_pop_heap(ptr noundef %2, ptr noundef nonnull %.0.lcssa, ptr noundef %4, ptr noundef %5)
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(36) %11, ptr noundef nonnull align 4 dereferenceable(36) %.15266, i64 36, i1 false), !tbaa.struct !5
  tail call void @person_array_push_heap(ptr noundef %2, ptr noundef nonnull %.0.lcssa, ptr noundef %4, ptr noundef %5)
  br label %19

19:                                               ; preds = %18, %15
  %20 = getelementptr inbounds i8, ptr %.15266, i64 36
  %.not57 = icmp eq ptr %20, %1
  br i1 %.not57, label %.sink.split, label %15, !llvm.loop !13

.sink.split:                                      ; preds = %.lr.ph, %19, %.preheader
  %.062.lcssa.sink = phi ptr [ %.0.lcssa, %.preheader ], [ %.0.lcssa, %19 ], [ %.062, %.lr.ph ]
  tail call void @person_array_sort_heap(ptr noundef %2, ptr noundef nonnull %.062.lcssa.sink, ptr noundef %4, ptr noundef %5)
  br label %21

21:                                               ; preds = %.sink.split, %6
  %.1 = phi ptr [ %2, %6 ], [ %.062.lcssa.sink, %.sink.split ]
  ret ptr %.1
}

attributes #0 = { mustprogress nocallback nofree 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 = !{i64 0, i64 4, !6, i64 4, i64 32, !10}
!6 = !{!7, !7, i64 0}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!8, !8, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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