; LLVM IR from iksha-rudra/Computational-Geometry :: CGAlgorithms/DataStructures/minheap.ll (ZN7MinHeap7heapifyEii)

; 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 <{ %"class.std::vector", i32, [4 x i8] }>
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<MinHeap::Node, std::allocator<MinHeap::Node>>::_Vector_impl" }
%"struct.std::_Vector_base<MinHeap::Node, std::allocator<MinHeap::Node>>::_Vector_impl" = type { %"struct.std::_Vector_base<MinHeap::Node, std::allocator<MinHeap::Node>>::_Vector_impl_data" }
%"struct.std::_Vector_base<MinHeap::Node, std::allocator<MinHeap::Node>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"struct.MinHeap::Node" = type { %class.Point, double }
%class.Point = type { 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 nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorIN7MinHeap4NodeESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #1 align 2

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

19:                                               ; preds = %3
  %20 = getelementptr inbounds %class.MinHeap, ptr %11, i32 0, i32 0
  %21 = load i32, ptr %7, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorIN7MinHeap4NodeESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %20, i64 noundef %22) #3
  %24 = getelementptr inbounds %"struct.MinHeap::Node", ptr %23, i32 0, i32 1
  %25 = load double, ptr %24, align 8, !tbaa !11
  %26 = getelementptr inbounds %class.MinHeap, ptr %11, i32 0, i32 0
  %27 = load i32, ptr %5, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorIN7MinHeap4NodeESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %26, i64 noundef %28) #3
  %30 = getelementptr inbounds %"struct.MinHeap::Node", ptr %29, i32 0, i32 1
  %31 = load double, ptr %30, align 8, !tbaa !11
  %32 = fcmp olt double %25, %31
  br i1 %32, label %33, label %35

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

35:                                               ; preds = %19, %3
  %36 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %36, ptr %9, align 4, !tbaa !9
  br label %37

37:                                               ; preds = %35, %33
  %38 = load i32, ptr %8, align 4, !tbaa !9
  %39 = load i32, ptr %6, align 4, !tbaa !9
  %40 = icmp slt i32 %38, %39
  br i1 %40, label %41, label %57

41:                                               ; preds = %37
  %42 = getelementptr inbounds %class.MinHeap, ptr %11, i32 0, i32 0
  %43 = load i32, ptr %8, align 4, !tbaa !9
  %44 = sext i32 %43 to i64
  %45 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorIN7MinHeap4NodeESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %42, i64 noundef %44) #3
  %46 = getelementptr inbounds %"struct.MinHeap::Node", ptr %45, i32 0, i32 1
  %47 = load double, ptr %46, align 8, !tbaa !11
  %48 = getelementptr inbounds %class.MinHeap, ptr %11, i32 0, i32 0
  %49 = load i32, ptr %9, align 4, !tbaa !9
  %50 = sext i32 %49 to i64
  %51 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorIN7MinHeap4NodeESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %48, i64 noundef %50) #3
  %52 = getelementptr inbounds %"struct.MinHeap::Node", ptr %51, i32 0, i32 1
  %53 = load double, ptr %52, align 8, !tbaa !11
  %54 = fcmp olt double %47, %53
  br i1 %54, label %55, label %57

55:                                               ; preds = %41
  %56 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %56, ptr %9, align 4, !tbaa !9
  br label %57

57:                                               ; preds = %55, %41, %37
  %58 = load i32, ptr %9, align 4, !tbaa !9
  %59 = load i32, ptr %5, align 4, !tbaa !9
  %60 = icmp ne i32 %58, %59
  br i1 %60, label %61, label %70

61:                                               ; preds = %57
  %62 = getelementptr inbounds %class.MinHeap, ptr %11, i32 0, i32 0
  %63 = load i32, ptr %5, align 4, !tbaa !9
  %64 = sext i32 %63 to i64
  %65 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorIN7MinHeap4NodeESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %62, i64 noundef %64) #3
  %66 = getelementptr inbounds %class.MinHeap, ptr %11, i32 0, i32 0
  %67 = load i32, ptr %9, align 4, !tbaa !9
  %68 = sext i32 %67 to i64
  %69 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorIN7MinHeap4NodeESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %66, i64 noundef %68) #3
  call void @_ZN7MinHeap4swapERNS_4NodeES1_(ptr noundef nonnull align 8 dereferenceable(28) %11, ptr noundef nonnull align 8 dereferenceable(16) %65, ptr noundef nonnull align 8 dereferenceable(16) %69)
  br label %71

70:                                               ; preds = %57
  store i32 1, ptr %10, align 4
  br label %74

71:                                               ; preds = %61
  %72 = load i32, ptr %9, align 4, !tbaa !9
  %73 = load i32, ptr %6, align 4, !tbaa !9
  call void @_ZN7MinHeap7heapifyEii(ptr noundef nonnull align 8 dereferenceable(28) %11, i32 noundef %72, i32 noundef %73)
  store i32 0, ptr %10, align 4
  br label %74

74:                                               ; preds = %71, %70
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  %75 = load i32, ptr %10, align 4
  switch i32 %75, label %77 [
    i32 0, label %76
    i32 1, label %76
  ]

76:                                               ; preds = %74, %74
  ret void

77:                                               ; preds = %74
  unreachable
}

; 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 void @_ZN7MinHeap4swapERNS_4NodeES1_(ptr noundef nonnull align 8 dereferenceable(28), ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) #1 align 2

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

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #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, !14, i64 8}
!12 = !{!"_ZTSN7MinHeap4NodeE", !13, i64 0, !14, i64 8}
!13 = !{!"_ZTS5Point", !10, i64 0, !10, i64 4}
!14 = !{!"double", !7, 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
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorIN7MinHeap4NodeESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN7MinHeap7heapifyEii(ptr noundef nonnull align 8 dereferenceable(28) %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 align 2 {
  br label %tailrecurse

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

7:                                                ; preds = %tailrecurse
  %8 = sext i32 %4 to i64
  %9 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorIN7MinHeap4NodeESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %8) #1
  %10 = getelementptr inbounds i8, ptr %9, i64 8
  %11 = load double, ptr %10, align 8, !tbaa !5
  %12 = sext i32 %.tr22 to i64
  %13 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorIN7MinHeap4NodeESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %12) #1
  %14 = getelementptr inbounds i8, ptr %13, i64 8
  %15 = load double, ptr %14, align 8, !tbaa !5
  %16 = fcmp olt double %11, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %7, %tailrecurse
  br label %18

18:                                               ; preds = %7, %17
  %.0 = phi i32 [ %.tr22, %17 ], [ %4, %7 ]
  %19 = icmp slt i32 %5, %2
  br i1 %19, label %20, label %31

20:                                               ; preds = %18
  %21 = sext i32 %5 to i64
  %22 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorIN7MinHeap4NodeESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %21) #1
  %23 = getelementptr inbounds i8, ptr %22, i64 8
  %24 = load double, ptr %23, align 8, !tbaa !5
  %25 = sext i32 %.0 to i64
  %26 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorIN7MinHeap4NodeESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %25) #1
  %27 = getelementptr inbounds i8, ptr %26, i64 8
  %28 = load double, ptr %27, align 8, !tbaa !5
  %29 = fcmp olt double %24, %28
  br i1 %29, label %30, label %31

30:                                               ; preds = %20
  br label %31

31:                                               ; preds = %30, %20, %18
  %.1 = phi i32 [ %5, %30 ], [ %.0, %20 ], [ %.0, %18 ]
  %.not = icmp eq i32 %.1, %.tr22
  br i1 %.not, label %37, label %32

32:                                               ; preds = %31
  %33 = sext i32 %.tr22 to i64
  %34 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorIN7MinHeap4NodeESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %33) #1
  %35 = sext i32 %.1 to i64
  %36 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorIN7MinHeap4NodeESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %35) #1
  tail call void @_ZN7MinHeap4swapERNS_4NodeES1_(ptr noundef nonnull align 8 dereferenceable(28) %0, ptr noundef nonnull align 8 dereferenceable(16) %34, ptr noundef nonnull align 8 dereferenceable(16) %36)
  br label %tailrecurse

37:                                               ; preds = %31
  ret void
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN7MinHeap4leftEi(ptr noundef nonnull align 8 dereferenceable(28), 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(28), i32 noundef) local_unnamed_addr #0 align 2

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" }
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)"}
!5 = !{!6, !11, i64 8}
!6 = !{!"_ZTSN7MinHeap4NodeE", !7, i64 0, !11, i64 8}
!7 = !{!"_ZTS5Point", !8, i64 0, !8, i64 4}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"double", !9, i64 0}


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