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

; 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 @intv_swap(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @intv_push_heap_n(ptr noundef %0, i64 noundef %1, ptr noundef %2, ptr noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  %14 = load i64, ptr %6, align 8, !tbaa !9
  %15 = icmp ule i64 %14, 1
  br i1 %15, label %16, label %17

16:                                               ; preds = %4
  br label %48

17:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %18 = load i64, ptr %6, align 8, !tbaa !9
  %19 = sub i64 %18, 1
  store i64 %19, ptr %9, align 8, !tbaa !9
  br label %20

20:                                               ; preds = %46, %17
  %21 = load i64, ptr %9, align 8, !tbaa !9
  %22 = icmp ne i64 %21, 0
  br i1 %22, label %23, label %47

23:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %24 = load i64, ptr %9, align 8, !tbaa !9
  %25 = sub i64 %24, 1
  %26 = lshr i64 %25, 1
  store i64 %26, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = load i64, ptr %9, align 8, !tbaa !9
  %29 = getelementptr inbounds i32, ptr %27, i64 %28
  store ptr %29, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = load i64, ptr %10, align 8, !tbaa !9
  %32 = getelementptr inbounds i32, ptr %30, i64 %31
  store ptr %32, ptr %12, align 8, !tbaa !5
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = load ptr, ptr %11, align 8, !tbaa !5
  %35 = load ptr, ptr %12, align 8, !tbaa !5
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = call i32 %33(ptr noundef %34, ptr noundef %35, ptr noundef %36)
  %38 = icmp sle i32 %37, 0
  br i1 %38, label %39, label %40

39:                                               ; preds = %23
  store i32 3, ptr %13, align 4
  br label %44

40:                                               ; preds = %23
  %41 = load ptr, ptr %11, align 8, !tbaa !5
  %42 = load ptr, ptr %12, align 8, !tbaa !5
  call void @intv_swap(ptr noundef %41, ptr noundef %42)
  %43 = load i64, ptr %10, align 8, !tbaa !9
  store i64 %43, ptr %9, align 8, !tbaa !9
  store i32 0, ptr %13, align 4
  br label %44

44:                                               ; preds = %40, %39
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  %45 = load i32, ptr %13, align 4
  switch i32 %45, label %49 [
    i32 0, label %46
    i32 3, label %47
  ]

46:                                               ; preds = %44
  br label %20, !llvm.loop !11

47:                                               ; preds = %44, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  br label %48

48:                                               ; preds = %47, %16
  ret void

49:                                               ; preds = %44
  unreachable
}

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


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

; Function Attrs: nounwind uwtable
define dso_local void @intv_push_heap_n(ptr noundef %0, i64 noundef %1, ptr nocapture noundef readonly %2, ptr noundef %3) local_unnamed_addr #0 {
  %or.cond = icmp ult i64 %1, 2
  br i1 %or.cond, label %.thread, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %4
  %5 = add i64 %1, -1
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %12
  %.01521 = phi i64 [ %7, %12 ], [ %5, %.lr.ph.preheader ]
  %6 = add i64 %.01521, -1
  %7 = lshr i64 %6, 1
  %8 = getelementptr inbounds i32, ptr %0, i64 %.01521
  %9 = getelementptr inbounds i32, ptr %0, i64 %7
  %10 = tail call i32 %2(ptr noundef nonnull %8, ptr noundef %9, ptr noundef %3) #1
  %11 = icmp slt i32 %10, 1
  br i1 %11, label %.thread, label %12

12:                                               ; preds = %.lr.ph
  tail call void @intv_swap(ptr noundef nonnull %8, ptr noundef %9)
  %.not = icmp ult i64 %6, 2
  br i1 %.not, label %.thread, label %.lr.ph

.thread:                                          ; preds = %12, %.lr.ph, %4
  ret void
}

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 = { 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)"}


; Effective O3 passes: GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass