; LLVM IR from PacktPublishing/CPP-Data-Structures-and-Algorithms :: Chapter07/Binary_Heap/src/BinaryHeap.ll (ZN10BinaryHeap9ShiftDownEi)

; 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.BinaryHeap = 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<int, std::allocator<int>>::_Vector_impl" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" = type { ptr, ptr, ptr }

; 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: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZSt4swapIiENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN10BinaryHeap9ShiftDownEi(ptr noundef nonnull align 8 dereferenceable(28) %0, i32 noundef %1) #3 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %6 = load ptr, ptr %3, align 8
  %7 = load i32, ptr %4, align 4, !tbaa !9
  %8 = getelementptr inbounds %class.BinaryHeap, ptr %6, i32 0, i32 1
  %9 = load i32, ptr %8, align 8, !tbaa !11
  %10 = icmp sgt i32 %7, %9
  br i1 %10, label %11, label %12

11:                                               ; preds = %2
  br label %72

12:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %13 = load i32, ptr %4, align 4, !tbaa !9
  store i32 %13, ptr %5, align 4, !tbaa !9
  %14 = load i32, ptr %4, align 4, !tbaa !9
  %15 = call noundef i32 @_ZN10BinaryHeap1lEi(ptr noundef nonnull align 8 dereferenceable(28) %6, i32 noundef %14)
  %16 = getelementptr inbounds %class.BinaryHeap, ptr %6, i32 0, i32 1
  %17 = load i32, ptr %16, align 8, !tbaa !11
  %18 = icmp sle i32 %15, %17
  br i1 %18, label %19, label %35

19:                                               ; preds = %12
  %20 = getelementptr inbounds %class.BinaryHeap, ptr %6, i32 0, i32 0
  %21 = load i32, ptr %4, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %20, i64 noundef %22) #4
  %24 = load i32, ptr %23, align 4, !tbaa !9
  %25 = getelementptr inbounds %class.BinaryHeap, ptr %6, i32 0, i32 0
  %26 = load i32, ptr %4, align 4, !tbaa !9
  %27 = call noundef i32 @_ZN10BinaryHeap1lEi(ptr noundef nonnull align 8 dereferenceable(28) %6, i32 noundef %26)
  %28 = sext i32 %27 to i64
  %29 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %25, i64 noundef %28) #4
  %30 = load i32, ptr %29, align 4, !tbaa !9
  %31 = icmp slt i32 %24, %30
  br i1 %31, label %32, label %35

32:                                               ; preds = %19
  %33 = load i32, ptr %4, align 4, !tbaa !9
  %34 = call noundef i32 @_ZN10BinaryHeap1lEi(ptr noundef nonnull align 8 dereferenceable(28) %6, i32 noundef %33)
  store i32 %34, ptr %5, align 4, !tbaa !9
  br label %35

35:                                               ; preds = %32, %19, %12
  %36 = load i32, ptr %4, align 4, !tbaa !9
  %37 = call noundef i32 @_ZN10BinaryHeap1rEi(ptr noundef nonnull align 8 dereferenceable(28) %6, i32 noundef %36)
  %38 = getelementptr inbounds %class.BinaryHeap, ptr %6, i32 0, i32 1
  %39 = load i32, ptr %38, align 8, !tbaa !11
  %40 = icmp sle i32 %37, %39
  br i1 %40, label %41, label %57

41:                                               ; preds = %35
  %42 = getelementptr inbounds %class.BinaryHeap, ptr %6, i32 0, i32 0
  %43 = load i32, ptr %5, align 4, !tbaa !9
  %44 = sext i32 %43 to i64
  %45 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %42, i64 noundef %44) #4
  %46 = load i32, ptr %45, align 4, !tbaa !9
  %47 = getelementptr inbounds %class.BinaryHeap, ptr %6, i32 0, i32 0
  %48 = load i32, ptr %4, align 4, !tbaa !9
  %49 = call noundef i32 @_ZN10BinaryHeap1rEi(ptr noundef nonnull align 8 dereferenceable(28) %6, i32 noundef %48)
  %50 = sext i32 %49 to i64
  %51 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %47, i64 noundef %50) #4
  %52 = load i32, ptr %51, align 4, !tbaa !9
  %53 = icmp slt i32 %46, %52
  br i1 %53, label %54, label %57

54:                                               ; preds = %41
  %55 = load i32, ptr %4, align 4, !tbaa !9
  %56 = call noundef i32 @_ZN10BinaryHeap1rEi(ptr noundef nonnull align 8 dereferenceable(28) %6, i32 noundef %55)
  store i32 %56, ptr %5, align 4, !tbaa !9
  br label %57

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

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

71:                                               ; preds = %61, %57
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %72

72:                                               ; preds = %71, %11
  ret void
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN10BinaryHeap1rEi(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 = { inlinehint 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 = { 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 #4 = { 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 24}
!12 = !{!"_ZTS10BinaryHeap", !13, i64 0, !10, i64 24}
!13 = !{!"_ZTSSt6vectorIiSaIiEE", !14, i64 0}
!14 = !{!"_ZTSSt12_Vector_baseIiSaIiEE", !15, i64 0}
!15 = !{!"_ZTSNSt12_Vector_baseIiSaIiEE12_Vector_implE", !16, i64 0}
!16 = !{!"_ZTSNSt12_Vector_baseIiSaIiEE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}


; 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 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZSt4swapIiENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN10BinaryHeap9ShiftDownEi(ptr noundef nonnull align 8 dereferenceable(28) %0, i32 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 24
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = icmp slt i32 %4, %1
  br i1 %5, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2, %tailrecurse
  %.tr1819 = phi i32 [ %.1, %tailrecurse ], [ %1, %2 ]
  %6 = tail call noundef i32 @_ZN10BinaryHeap1lEi(ptr noundef nonnull align 8 dereferenceable(28) %0, i32 noundef %.tr1819)
  %7 = load i32, ptr %3, align 8, !tbaa !5
  %.not = icmp sgt i32 %6, %7
  br i1 %.not, label %19, label %8

8:                                                ; preds = %.lr.ph
  %9 = sext i32 %.tr1819 to i64
  %10 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %9) #2
  %11 = load i32, ptr %10, align 4, !tbaa !15
  %12 = tail call noundef i32 @_ZN10BinaryHeap1lEi(ptr noundef nonnull align 8 dereferenceable(28) %0, i32 noundef %.tr1819)
  %13 = sext i32 %12 to i64
  %14 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %13) #2
  %15 = load i32, ptr %14, align 4, !tbaa !15
  %16 = icmp slt i32 %11, %15
  br i1 %16, label %17, label %19

17:                                               ; preds = %8
  %18 = tail call noundef i32 @_ZN10BinaryHeap1lEi(ptr noundef nonnull align 8 dereferenceable(28) %0, i32 noundef %.tr1819)
  br label %19

19:                                               ; preds = %17, %8, %.lr.ph
  %.0 = phi i32 [ %18, %17 ], [ %.tr1819, %8 ], [ %.tr1819, %.lr.ph ]
  %20 = tail call noundef i32 @_ZN10BinaryHeap1rEi(ptr noundef nonnull align 8 dereferenceable(28) %0, i32 noundef %.tr1819)
  %21 = load i32, ptr %3, align 8, !tbaa !5
  %.not16 = icmp sgt i32 %20, %21
  br i1 %.not16, label %33, label %22

22:                                               ; preds = %19
  %23 = sext i32 %.0 to i64
  %24 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %23) #2
  %25 = load i32, ptr %24, align 4, !tbaa !15
  %26 = tail call noundef i32 @_ZN10BinaryHeap1rEi(ptr noundef nonnull align 8 dereferenceable(28) %0, i32 noundef %.tr1819)
  %27 = sext i32 %26 to i64
  %28 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %27) #2
  %29 = load i32, ptr %28, align 4, !tbaa !15
  %30 = icmp slt i32 %25, %29
  br i1 %30, label %31, label %33

31:                                               ; preds = %22
  %32 = tail call noundef i32 @_ZN10BinaryHeap1rEi(ptr noundef nonnull align 8 dereferenceable(28) %0, i32 noundef %.tr1819)
  br label %33

33:                                               ; preds = %31, %22, %19
  %.1 = phi i32 [ %32, %31 ], [ %.0, %22 ], [ %.0, %19 ]
  %.not17 = icmp eq i32 %.1, %.tr1819
  br i1 %.not17, label %._crit_edge, label %tailrecurse

tailrecurse:                                      ; preds = %33
  %34 = sext i32 %.tr1819 to i64
  %35 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %34) #2
  %36 = sext i32 %.1 to i64
  %37 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %36) #2
  tail call void @_ZSt4swapIiENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 4 dereferenceable(4) %35, ptr noundef nonnull align 4 dereferenceable(4) %37) #2
  %38 = load i32, ptr %3, align 8, !tbaa !5
  %39 = icmp slt i32 %38, %.1
  br i1 %39, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %tailrecurse, %33, %2
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN10BinaryHeap1lEi(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 @_ZN10BinaryHeap1rEi(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 = { inlinehint 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 = { 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, !14, i64 24}
!6 = !{!"_ZTS10BinaryHeap", !7, i64 0, !14, i64 24}
!7 = !{!"_ZTSSt6vectorIiSaIiEE", !8, i64 0}
!8 = !{!"_ZTSSt12_Vector_baseIiSaIiEE", !9, i64 0}
!9 = !{!"_ZTSNSt12_Vector_baseIiSaIiEE12_Vector_implE", !10, i64 0}
!10 = !{!"_ZTSNSt12_Vector_baseIiSaIiEE17_Vector_impl_dataE", !11, i64 0, !11, i64 8, !11, i64 16}
!11 = !{!"any pointer", !12, i64 0}
!12 = !{!"omnipotent char", !13, i64 0}
!13 = !{!"Simple C++ TBAA"}
!14 = !{!"int", !12, i64 0}
!15 = !{!14, !14, i64 0}


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