; LLVM IR from PetarV-/Algorithms :: Data Structures/Pairing Heap.ll (ZN5PHeap6DeleteEP5PNode)

; 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.PHeap = type { ptr }
%struct.PNode = type { i32, ptr, ptr, ptr }

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

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) #1

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) #2

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

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN5PHeap10extractMinEv(ptr noundef nonnull align 8 dereferenceable(8)) #4 align 2

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

13:                                               ; preds = %2
  %14 = call noundef ptr @_ZN5PHeap10extractMinEv(ptr noundef nonnull align 8 dereferenceable(8) %8)
  br label %76

15:                                               ; preds = %2
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.PNode, ptr %16, i32 0, i32 1
  %18 = load ptr, ptr %17, align 8, !tbaa !11
  %19 = getelementptr inbounds %struct.PNode, ptr %18, i32 0, i32 3
  %20 = load ptr, ptr %19, align 8, !tbaa !14
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = icmp eq ptr %20, %21
  br i1 %22, label %23, label %44

23:                                               ; preds = %15
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.PNode, ptr %24, i32 0, i32 2
  %26 = load ptr, ptr %25, align 8, !tbaa !15
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.PNode, ptr %27, i32 0, i32 1
  %29 = load ptr, ptr %28, align 8, !tbaa !11
  %30 = getelementptr inbounds %struct.PNode, ptr %29, i32 0, i32 3
  store ptr %26, ptr %30, align 8, !tbaa !14
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.PNode, ptr %31, i32 0, i32 2
  %33 = load ptr, ptr %32, align 8, !tbaa !15
  %34 = icmp ne ptr %33, null
  br i1 %34, label %35, label %43

35:                                               ; preds = %23
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.PNode, ptr %36, i32 0, i32 1
  %38 = load ptr, ptr %37, align 8, !tbaa !11
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.PNode, ptr %39, i32 0, i32 2
  %41 = load ptr, ptr %40, align 8, !tbaa !15
  %42 = getelementptr inbounds %struct.PNode, ptr %41, i32 0, i32 1
  store ptr %38, ptr %42, align 8, !tbaa !11
  br label %43

43:                                               ; preds = %35, %23
  br label %65

44:                                               ; preds = %15
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.PNode, ptr %45, i32 0, i32 2
  %47 = load ptr, ptr %46, align 8, !tbaa !15
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.PNode, ptr %48, i32 0, i32 1
  %50 = load ptr, ptr %49, align 8, !tbaa !11
  %51 = getelementptr inbounds %struct.PNode, ptr %50, i32 0, i32 2
  store ptr %47, ptr %51, align 8, !tbaa !15
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.PNode, ptr %52, i32 0, i32 2
  %54 = load ptr, ptr %53, align 8, !tbaa !15
  %55 = icmp ne ptr %54, null
  br i1 %55, label %56, label %64

56:                                               ; preds = %44
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.PNode, ptr %57, i32 0, i32 1
  %59 = load ptr, ptr %58, align 8, !tbaa !11
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.PNode, ptr %60, i32 0, i32 2
  %62 = load ptr, ptr %61, align 8, !tbaa !15
  %63 = getelementptr inbounds %struct.PNode, ptr %62, i32 0, i32 1
  store ptr %59, ptr %63, align 8, !tbaa !11
  br label %64

64:                                               ; preds = %56, %44
  br label %65

65:                                               ; preds = %64, %43
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %66 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 8) #6
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  invoke void @_ZN5PHeapC1EP5PNode(ptr noundef nonnull align 8 dereferenceable(8) %66, ptr noundef %67)
          to label %68 unwind label %72

68:                                               ; preds = %65
  store ptr %66, ptr %5, align 8, !tbaa !5
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  %70 = call noundef ptr @_ZN5PHeap10extractMinEv(ptr noundef nonnull align 8 dereferenceable(8) %69)
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  call void @_ZN5PHeap5mergeEPS_(ptr noundef nonnull align 8 dereferenceable(8) %8, ptr noundef %71)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  br label %76

72:                                               ; preds = %65
  %73 = landingpad { ptr, i32 }
          cleanup
  %74 = extractvalue { ptr, i32 } %73, 0
  store ptr %74, ptr %6, align 8
  %75 = extractvalue { ptr, i32 } %73, 1
  store i32 %75, ptr %7, align 4
  call void @_ZdlPvm(ptr noundef %66, i64 noundef 8) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  br label %77

76:                                               ; preds = %68, %13
  ret void

77:                                               ; preds = %72
  %78 = load ptr, ptr %6, align 8
  %79 = load i32, ptr %7, align 4
  %80 = insertvalue { ptr, i32 } poison, ptr %78, 0
  %81 = insertvalue { ptr, i32 } %80, i32 %79, 1
  resume { ptr, i32 } %81
}

declare void @_ZN5PHeapC1EP5PNode(ptr, ptr)

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 = { nobuiltin allocsize(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 = { nobuiltin nounwind "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #5 = { nounwind }
attributes #6 = { builtin allocsize(0) }
attributes #7 = { builtin 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, !6, i64 0}
!10 = !{!"_ZTS5PHeap", !6, i64 0}
!11 = !{!12, !6, i64 8}
!12 = !{!"_ZTS5PNode", !13, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !6, i64 24}
!15 = !{!12, !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 void @_ZN5PHeap5mergeEPS_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) local_unnamed_addr #0 align 2

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) local_unnamed_addr #1

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN5PHeap10extractMinEv(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN5PHeap6DeleteEP5PNode(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef %1) local_unnamed_addr #3 align 2 personality ptr @__gxx_personality_v0 {
  %3 = load ptr, ptr %0, align 8, !tbaa !5
  %4 = icmp eq ptr %3, %1
  br i1 %4, label %5, label %7

5:                                                ; preds = %2
  %6 = tail call noundef ptr @_ZN5PHeap10extractMinEv(ptr noundef nonnull align 8 dereferenceable(8) %0)
  br label %25

7:                                                ; preds = %2
  %8 = getelementptr inbounds i8, ptr %1, i64 8
  %9 = load ptr, ptr %8, align 8, !tbaa !10
  %10 = getelementptr inbounds i8, ptr %9, i64 24
  %11 = load ptr, ptr %10, align 8, !tbaa !13
  %12 = icmp eq ptr %11, %1
  %13 = getelementptr inbounds i8, ptr %1, i64 16
  %14 = load ptr, ptr %13, align 8, !tbaa !14
  br i1 %12, label %15, label %16

15:                                               ; preds = %7
  store ptr %14, ptr %10, align 8, !tbaa !13
  %.not20 = icmp eq ptr %14, null
  br i1 %.not20, label %19, label %.sink.split

16:                                               ; preds = %7
  %17 = getelementptr inbounds i8, ptr %9, i64 16
  store ptr %14, ptr %17, align 8, !tbaa !14
  %.not = icmp eq ptr %14, null
  br i1 %.not, label %19, label %.sink.split

.sink.split:                                      ; preds = %16, %15
  %18 = getelementptr inbounds i8, ptr %14, i64 8
  store ptr %9, ptr %18, align 8, !tbaa !10
  br label %19

19:                                               ; preds = %.sink.split, %16, %15
  %20 = tail call noalias noundef nonnull dereferenceable(8) ptr @_Znwm(i64 noundef 8) #4
  invoke void @_ZN5PHeapC1EP5PNode(ptr noundef nonnull align 8 dereferenceable(8) %20, ptr noundef nonnull %1)
          to label %21 unwind label %23

21:                                               ; preds = %19
  %22 = tail call noundef ptr @_ZN5PHeap10extractMinEv(ptr noundef nonnull align 8 dereferenceable(8) %20)
  tail call void @_ZN5PHeap5mergeEPS_(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef nonnull %20)
  br label %25

23:                                               ; preds = %19
  %24 = landingpad { ptr, i32 }
          cleanup
  tail call void @_ZdlPvm(ptr noundef nonnull %20, i64 noundef 8) #5
  resume { ptr, i32 } %24

25:                                               ; preds = %21, %5
  ret void
}

declare void @_ZN5PHeapC1EP5PNode(ptr, ptr) local_unnamed_addr

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 = { nobuiltin allocsize(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 = { nobuiltin nounwind "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 = { builtin allocsize(0) }
attributes #5 = { builtin 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, !7, i64 0}
!6 = !{!"_ZTS5PHeap", !7, i64 0}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!11, !7, i64 8}
!11 = !{!"_ZTS5PNode", !12, i64 0, !7, i64 8, !7, i64 16, !7, i64 24}
!12 = !{!"int", !8, i64 0}
!13 = !{!11, !7, i64 24}
!14 = !{!11, !7, i64 16}


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