; LLVM IR from div-bargali/Data-Structures-and-Algorithms :: C++/Data-Structures/Heap/Heap (Kth Largest Element in a Stream ) C++/KthLargestEl_91a32f09 (ZN7MinHeap10MinHeapifyEi)

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

%class.MinHeap = type { ptr, i32, i32 }

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7MinHeap10MinHeapifyEi(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %8 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %9 = load i32, ptr %4, align 4, !tbaa !9
  %10 = call noundef i32 @_ZN7MinHeap4leftEi(ptr noundef nonnull align 8 dereferenceable(16) %8, i32 noundef %9)
  store i32 %10, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %11 = load i32, ptr %4, align 4, !tbaa !9
  %12 = call noundef i32 @_ZN7MinHeap5rightEi(ptr noundef nonnull align 8 dereferenceable(16) %8, i32 noundef %11)
  store i32 %12, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %13 = load i32, ptr %4, align 4, !tbaa !9
  store i32 %13, ptr %7, align 4, !tbaa !9
  %14 = load i32, ptr %5, align 4, !tbaa !9
  %15 = getelementptr inbounds %class.MinHeap, ptr %8, i32 0, i32 2
  %16 = load i32, ptr %15, align 4, !tbaa !11
  %17 = icmp slt i32 %14, %16
  br i1 %17, label %18, label %34

18:                                               ; preds = %2
  %19 = getelementptr inbounds %class.MinHeap, ptr %8, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8, !tbaa !13
  %21 = load i32, ptr %5, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds i32, ptr %20, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !9
  %25 = getelementptr inbounds %class.MinHeap, ptr %8, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !13
  %27 = load i32, ptr %4, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds i32, ptr %26, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !9
  %31 = icmp slt i32 %24, %30
  br i1 %31, label %32, label %34

32:                                               ; preds = %18
  %33 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %33, ptr %7, align 4, !tbaa !9
  br label %34

34:                                               ; preds = %32, %18, %2
  %35 = load i32, ptr %6, align 4, !tbaa !9
  %36 = getelementptr inbounds %class.MinHeap, ptr %8, i32 0, i32 2
  %37 = load i32, ptr %36, align 4, !tbaa !11
  %38 = icmp slt i32 %35, %37
  br i1 %38, label %39, label %55

39:                                               ; preds = %34
  %40 = getelementptr inbounds %class.MinHeap, ptr %8, i32 0, i32 0
  %41 = load ptr, ptr %40, align 8, !tbaa !13
  %42 = load i32, ptr %6, align 4, !tbaa !9
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds i32, ptr %41, i64 %43
  %45 = load i32, ptr %44, align 4, !tbaa !9
  %46 = getelementptr inbounds %class.MinHeap, ptr %8, i32 0, i32 0
  %47 = load ptr, ptr %46, align 8, !tbaa !13
  %48 = load i32, ptr %7, align 4, !tbaa !9
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds i32, ptr %47, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !9
  %52 = icmp slt i32 %45, %51
  br i1 %52, label %53, label %55

53:                                               ; preds = %39
  %54 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %54, ptr %7, align 4, !tbaa !9
  br label %55

55:                                               ; preds = %53, %39, %34
  %56 = load i32, ptr %7, align 4, !tbaa !9
  %57 = load i32, ptr %4, align 4, !tbaa !9
  %58 = icmp ne i32 %56, %57
  br i1 %58, label %59, label %71

59:                                               ; preds = %55
  %60 = getelementptr inbounds %class.MinHeap, ptr %8, i32 0, i32 0
  %61 = load ptr, ptr %60, align 8, !tbaa !13
  %62 = load i32, ptr %4, align 4, !tbaa !9
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds i32, ptr %61, i64 %63
  %65 = getelementptr inbounds %class.MinHeap, ptr %8, i32 0, i32 0
  %66 = load ptr, ptr %65, align 8, !tbaa !13
  %67 = load i32, ptr %7, align 4, !tbaa !9
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds i32, ptr %66, i64 %68
  call void @_Z4swapPiS_(ptr noundef %64, ptr noundef %69)
  %70 = load i32, ptr %7, align 4, !tbaa !9
  call void @_ZN7MinHeap10MinHeapifyEi(ptr noundef nonnull align 8 dereferenceable(16) %8, i32 noundef %70)
  br label %71

71:                                               ; preds = %59, %55
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret void
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN7MinHeap4leftEi(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN7MinHeap5rightEi(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) #2 align 2

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { mustprogress 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 12}
!12 = !{!"_ZTS7MinHeap", !6, i64 0, !10, i64 8, !10, i64 12}
!13 = !{!12, !6, i64 0}


; 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 nounwind uwtable
define dso_local void @_ZN7MinHeap10MinHeapifyEi(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 12
  br label %tailrecurse

tailrecurse:                                      ; preds = %29, %2
  %.tr20 = phi i32 [ %1, %2 ], [ %.1, %29 ]
  %4 = tail call noundef i32 @_ZN7MinHeap4leftEi(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %.tr20)
  %5 = tail call noundef i32 @_ZN7MinHeap5rightEi(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %.tr20)
  %6 = load i32, ptr %3, align 4, !tbaa !5
  %7 = icmp slt i32 %4, %6
  br i1 %7, label %8, label %17

8:                                                ; preds = %tailrecurse
  %9 = load ptr, ptr %0, align 8, !tbaa !11
  %10 = sext i32 %4 to i64
  %11 = getelementptr inbounds i32, ptr %9, i64 %10
  %12 = load i32, ptr %11, align 4, !tbaa !12
  %13 = sext i32 %.tr20 to i64
  %14 = getelementptr inbounds i32, ptr %9, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !12
  %16 = icmp slt i32 %12, %15
  %spec.select = select i1 %16, i32 %4, i32 %.tr20
  br label %17

17:                                               ; preds = %8, %tailrecurse
  %.0 = phi i32 [ %.tr20, %tailrecurse ], [ %spec.select, %8 ]
  %18 = icmp slt i32 %5, %6
  br i1 %18, label %19, label %28

19:                                               ; preds = %17
  %20 = load ptr, ptr %0, align 8, !tbaa !11
  %21 = sext i32 %5 to i64
  %22 = getelementptr inbounds i32, ptr %20, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !12
  %24 = sext i32 %.0 to i64
  %25 = getelementptr inbounds i32, ptr %20, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !12
  %27 = icmp slt i32 %23, %26
  %spec.select19 = select i1 %27, i32 %5, i32 %.0
  br label %28

28:                                               ; preds = %19, %17
  %.1 = phi i32 [ %.0, %17 ], [ %spec.select19, %19 ]
  %.not = icmp eq i32 %.1, %.tr20
  br i1 %.not, label %35, label %29

29:                                               ; preds = %28
  %30 = load ptr, ptr %0, align 8, !tbaa !11
  %31 = sext i32 %.tr20 to i64
  %32 = getelementptr inbounds i32, ptr %30, i64 %31
  %33 = sext i32 %.1 to i64
  %34 = getelementptr inbounds i32, ptr %30, i64 %33
  tail call void @_Z4swapPiS_(ptr noundef %32, ptr noundef %34)
  br label %tailrecurse

35:                                               ; preds = %28
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN7MinHeap4leftEi(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN7MinHeap5rightEi(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z4swapPiS_(ptr noundef, ptr noundef) local_unnamed_addr #0

attributes #0 = { mustprogress 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" }

!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, !10, i64 12}
!6 = !{!"_ZTS7MinHeap", !7, i64 0, !10, i64 8, !10, i64 12}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!10, !10, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass