; LLVM IR from mackorone/mms :: old/v2/src/mouse/mackAlgo/CellHeap.ll (ZN8mackAlgo8CellHeap9heapifyUpEi)

; 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.mackAlgo::CellHeap" = type { i32, i32, ptr }

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN8mackAlgo8CellHeap9heapifyUpEi(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %1) #0 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %5 = load ptr, ptr %3, align 8
  br label %6

6:                                                ; preds = %29, %2
  %7 = load i32, ptr %4, align 4, !tbaa !9
  %8 = call noundef i32 @_ZN8mackAlgo8CellHeap14getParentIndexEi(ptr noundef nonnull align 8 dereferenceable(16) %5, i32 noundef %7)
  %9 = icmp sle i32 0, %8
  br i1 %9, label %10, label %27

10:                                               ; preds = %6
  %11 = getelementptr inbounds %"class.mackAlgo::CellHeap", ptr %5, i32 0, i32 2
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  %13 = load i32, ptr %4, align 4, !tbaa !9
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds ptr, ptr %12, i64 %14
  %16 = load ptr, ptr %15, align 8, !tbaa !5
  %17 = call noundef float @_ZNK8mackAlgo4Cell11getDistanceEv(ptr noundef nonnull align 8 dereferenceable(53) %16)
  %18 = getelementptr inbounds %"class.mackAlgo::CellHeap", ptr %5, i32 0, i32 2
  %19 = load ptr, ptr %18, align 8, !tbaa !11
  %20 = load i32, ptr %4, align 4, !tbaa !9
  %21 = call noundef i32 @_ZN8mackAlgo8CellHeap14getParentIndexEi(ptr noundef nonnull align 8 dereferenceable(16) %5, i32 noundef %20)
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds ptr, ptr %19, i64 %22
  %24 = load ptr, ptr %23, align 8, !tbaa !5
  %25 = call noundef float @_ZNK8mackAlgo4Cell11getDistanceEv(ptr noundef nonnull align 8 dereferenceable(53) %24)
  %26 = fcmp olt float %17, %25
  br label %27

27:                                               ; preds = %10, %6
  %28 = phi i1 [ false, %6 ], [ %26, %10 ]
  br i1 %28, label %29, label %35

29:                                               ; preds = %27
  %30 = load i32, ptr %4, align 4, !tbaa !9
  %31 = load i32, ptr %4, align 4, !tbaa !9
  %32 = call noundef i32 @_ZN8mackAlgo8CellHeap14getParentIndexEi(ptr noundef nonnull align 8 dereferenceable(16) %5, i32 noundef %31)
  call void @_ZN8mackAlgo8CellHeap4swapEii(ptr noundef nonnull align 8 dereferenceable(16) %5, i32 noundef %30, i32 noundef %32)
  %33 = load i32, ptr %4, align 4, !tbaa !9
  %34 = call noundef i32 @_ZN8mackAlgo8CellHeap14getParentIndexEi(ptr noundef nonnull align 8 dereferenceable(16) %5, i32 noundef %33)
  store i32 %34, ptr %4, align 4, !tbaa !9
  br label %6, !llvm.loop !13

35:                                               ; preds = %27
  ret void
}

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

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

declare noundef float @_ZNK8mackAlgo4Cell11getDistanceEv(ptr noundef nonnull align 8 dereferenceable(53)) #2

attributes #0 = { 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 #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 = { "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, !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, !6, i64 8}
!12 = !{!"_ZTSN8mackAlgo8CellHeapE", !10, i64 0, !10, i64 4, !6, i64 8}
!13 = distinct !{!13, !14}
!14 = !{!"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: mustprogress uwtable
define dso_local void @_ZN8mackAlgo8CellHeap9heapifyUpEi(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = tail call noundef i32 @_ZN8mackAlgo8CellHeap14getParentIndexEi(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %1)
  %5 = icmp sgt i32 %4, -1
  br i1 %5, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %2, %18
  %.06 = phi i32 [ %20, %18 ], [ %1, %2 ]
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = sext i32 %.06 to i64
  %8 = getelementptr inbounds ptr, ptr %6, i64 %7
  %9 = load ptr, ptr %8, align 8, !tbaa !11
  %10 = tail call noundef float @_ZNK8mackAlgo4Cell11getDistanceEv(ptr noundef nonnull align 8 dereferenceable(53) %9)
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = tail call noundef i32 @_ZN8mackAlgo8CellHeap14getParentIndexEi(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %.06)
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds ptr, ptr %11, i64 %13
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  %16 = tail call noundef float @_ZNK8mackAlgo4Cell11getDistanceEv(ptr noundef nonnull align 8 dereferenceable(53) %15)
  %17 = fcmp olt float %10, %16
  br i1 %17, label %18, label %.critedge

18:                                               ; preds = %.lr.ph
  %19 = tail call noundef i32 @_ZN8mackAlgo8CellHeap14getParentIndexEi(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %.06)
  tail call void @_ZN8mackAlgo8CellHeap4swapEii(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %.06, i32 noundef %19)
  %20 = tail call noundef i32 @_ZN8mackAlgo8CellHeap14getParentIndexEi(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %.06)
  %21 = tail call noundef i32 @_ZN8mackAlgo8CellHeap14getParentIndexEi(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %20)
  %22 = icmp sgt i32 %21, -1
  br i1 %22, label %.lr.ph, label %.critedge, !llvm.loop !12

.critedge:                                        ; preds = %.lr.ph, %18, %2
  ret void
}

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

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

declare noundef float @_ZNK8mackAlgo4Cell11getDistanceEv(ptr noundef nonnull align 8 dereferenceable(53)) local_unnamed_addr #2

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


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