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

; 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 noundef zeroext i1 @_ZN5PHeap7isEmptyEv(ptr noundef nonnull align 8 dereferenceable(8)) #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN5PHeap5mergeEPS_(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef %1) #0 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = call noundef zeroext i1 @_ZN5PHeap7isEmptyEv(ptr noundef nonnull align 8 dereferenceable(8) %8)
  br i1 %9, label %10, label %11

10:                                               ; preds = %2
  br label %95

11:                                               ; preds = %2
  %12 = call noundef zeroext i1 @_ZN5PHeap7isEmptyEv(ptr noundef nonnull align 8 dereferenceable(8) %7)
  br i1 %12, label %13, label %18

13:                                               ; preds = %11
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %class.PHeap, ptr %14, i32 0, i32 0
  %16 = load ptr, ptr %15, align 8, !tbaa !9
  %17 = getelementptr inbounds %class.PHeap, ptr %7, i32 0, i32 0
  store ptr %16, ptr %17, align 8, !tbaa !9
  br label %95

18:                                               ; preds = %11
  %19 = getelementptr inbounds %class.PHeap, ptr %7, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8, !tbaa !9
  %21 = getelementptr inbounds %struct.PNode, ptr %20, i32 0, i32 0
  %22 = load i32, ptr %21, align 8, !tbaa !11
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %class.PHeap, ptr %23, i32 0, i32 0
  %25 = load ptr, ptr %24, align 8, !tbaa !9
  %26 = getelementptr inbounds %struct.PNode, ptr %25, i32 0, i32 0
  %27 = load i32, ptr %26, align 8, !tbaa !11
  %28 = icmp slt i32 %22, %27
  br i1 %28, label %29, label %60

29:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %30 = getelementptr inbounds %class.PHeap, ptr %7, i32 0, i32 0
  %31 = load ptr, ptr %30, align 8, !tbaa !9
  %32 = getelementptr inbounds %struct.PNode, ptr %31, i32 0, i32 3
  %33 = load ptr, ptr %32, align 8, !tbaa !14
  store ptr %33, ptr %5, align 8, !tbaa !5
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %class.PHeap, ptr %34, i32 0, i32 0
  %36 = load ptr, ptr %35, align 8, !tbaa !9
  %37 = getelementptr inbounds %class.PHeap, ptr %7, i32 0, i32 0
  %38 = load ptr, ptr %37, align 8, !tbaa !9
  %39 = getelementptr inbounds %struct.PNode, ptr %38, i32 0, i32 3
  store ptr %36, ptr %39, align 8, !tbaa !14
  %40 = getelementptr inbounds %class.PHeap, ptr %7, i32 0, i32 0
  %41 = load ptr, ptr %40, align 8, !tbaa !9
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %class.PHeap, ptr %42, i32 0, i32 0
  %44 = load ptr, ptr %43, align 8, !tbaa !9
  %45 = getelementptr inbounds %struct.PNode, ptr %44, i32 0, i32 1
  store ptr %41, ptr %45, align 8, !tbaa !15
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %class.PHeap, ptr %47, i32 0, i32 0
  %49 = load ptr, ptr %48, align 8, !tbaa !9
  %50 = getelementptr inbounds %struct.PNode, ptr %49, i32 0, i32 2
  store ptr %46, ptr %50, align 8, !tbaa !16
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = icmp ne ptr %51, null
  br i1 %52, label %53, label %59

53:                                               ; preds = %29
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %class.PHeap, ptr %54, i32 0, i32 0
  %56 = load ptr, ptr %55, align 8, !tbaa !9
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.PNode, ptr %57, i32 0, i32 1
  store ptr %56, ptr %58, align 8, !tbaa !15
  br label %59

59:                                               ; preds = %53, %29
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  br label %94

60:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = getelementptr inbounds %class.PHeap, ptr %61, i32 0, i32 0
  %63 = load ptr, ptr %62, align 8, !tbaa !9
  %64 = getelementptr inbounds %struct.PNode, ptr %63, i32 0, i32 3
  %65 = load ptr, ptr %64, align 8, !tbaa !14
  store ptr %65, ptr %6, align 8, !tbaa !5
  %66 = getelementptr inbounds %class.PHeap, ptr %7, i32 0, i32 0
  %67 = load ptr, ptr %66, align 8, !tbaa !9
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  %69 = getelementptr inbounds %class.PHeap, ptr %68, i32 0, i32 0
  %70 = load ptr, ptr %69, align 8, !tbaa !9
  %71 = getelementptr inbounds %struct.PNode, ptr %70, i32 0, i32 3
  store ptr %67, ptr %71, align 8, !tbaa !14
  %72 = load ptr, ptr %4, align 8, !tbaa !5
  %73 = getelementptr inbounds %class.PHeap, ptr %72, i32 0, i32 0
  %74 = load ptr, ptr %73, align 8, !tbaa !9
  %75 = getelementptr inbounds %class.PHeap, ptr %7, i32 0, i32 0
  %76 = load ptr, ptr %75, align 8, !tbaa !9
  %77 = getelementptr inbounds %struct.PNode, ptr %76, i32 0, i32 1
  store ptr %74, ptr %77, align 8, !tbaa !15
  %78 = load ptr, ptr %6, align 8, !tbaa !5
  %79 = getelementptr inbounds %class.PHeap, ptr %7, i32 0, i32 0
  %80 = load ptr, ptr %79, align 8, !tbaa !9
  %81 = getelementptr inbounds %struct.PNode, ptr %80, i32 0, i32 2
  store ptr %78, ptr %81, align 8, !tbaa !16
  %82 = load ptr, ptr %6, align 8, !tbaa !5
  %83 = icmp ne ptr %82, null
  br i1 %83, label %84, label %89

84:                                               ; preds = %60
  %85 = getelementptr inbounds %class.PHeap, ptr %7, i32 0, i32 0
  %86 = load ptr, ptr %85, align 8, !tbaa !9
  %87 = load ptr, ptr %6, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.PNode, ptr %87, i32 0, i32 1
  store ptr %86, ptr %88, align 8, !tbaa !15
  br label %89

89:                                               ; preds = %84, %60
  %90 = load ptr, ptr %4, align 8, !tbaa !5
  %91 = getelementptr inbounds %class.PHeap, ptr %90, i32 0, i32 0
  %92 = load ptr, ptr %91, align 8, !tbaa !9
  %93 = getelementptr inbounds %class.PHeap, ptr %7, i32 0, i32 0
  store ptr %92, ptr %93, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  br label %94

94:                                               ; preds = %89, %59
  br label %95

95:                                               ; preds = %94, %13, %10
  ret void
}

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

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !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, !13, i64 0}
!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 8}
!16 = !{!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 noundef zeroext i1 @_ZN5PHeap7isEmptyEv(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN5PHeap5mergeEPS_(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef nonnull %1) local_unnamed_addr #0 align 2 {
  %3 = tail call noundef zeroext i1 @_ZN5PHeap7isEmptyEv(ptr noundef nonnull align 8 dereferenceable(8) %1)
  br i1 %3, label %29, label %4

4:                                                ; preds = %2
  %5 = tail call noundef zeroext i1 @_ZN5PHeap7isEmptyEv(ptr noundef nonnull align 8 dereferenceable(8) %0)
  br i1 %5, label %6, label %8

6:                                                ; preds = %4
  %7 = load ptr, ptr %1, align 8, !tbaa !5
  store ptr %7, ptr %0, align 8, !tbaa !5
  br label %29

8:                                                ; preds = %4
  %9 = load ptr, ptr %0, align 8, !tbaa !5
  %10 = load i32, ptr %9, align 8, !tbaa !10
  %11 = load ptr, ptr %1, align 8, !tbaa !5
  %12 = load i32, ptr %11, align 8, !tbaa !10
  %13 = icmp slt i32 %10, %12
  br i1 %13, label %14, label %21

14:                                               ; preds = %8
  %15 = getelementptr inbounds i8, ptr %9, i64 24
  %16 = load ptr, ptr %15, align 8, !tbaa !13
  store ptr %11, ptr %15, align 8, !tbaa !13
  %17 = getelementptr inbounds i8, ptr %11, i64 8
  store ptr %9, ptr %17, align 8, !tbaa !14
  %18 = getelementptr inbounds i8, ptr %11, i64 16
  store ptr %16, ptr %18, align 8, !tbaa !15
  %.not19 = icmp eq ptr %16, null
  br i1 %.not19, label %29, label %19

19:                                               ; preds = %14
  %20 = getelementptr inbounds i8, ptr %16, i64 8
  store ptr %11, ptr %20, align 8, !tbaa !14
  br label %29

21:                                               ; preds = %8
  %22 = getelementptr inbounds i8, ptr %11, i64 24
  %23 = load ptr, ptr %22, align 8, !tbaa !13
  store ptr %9, ptr %22, align 8, !tbaa !13
  %24 = getelementptr inbounds i8, ptr %9, i64 8
  store ptr %11, ptr %24, align 8, !tbaa !14
  %25 = getelementptr inbounds i8, ptr %9, i64 16
  store ptr %23, ptr %25, align 8, !tbaa !15
  %.not = icmp eq ptr %23, null
  br i1 %.not, label %28, label %26

26:                                               ; preds = %21
  %27 = getelementptr inbounds i8, ptr %23, i64 8
  store ptr %9, ptr %27, align 8, !tbaa !14
  br label %28

28:                                               ; preds = %26, %21
  store ptr %11, ptr %0, align 8, !tbaa !5
  br label %29

29:                                               ; preds = %14, %19, %28, %2, %6
  ret void
}

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, !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, !12, i64 0}
!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 8}
!15 = !{!11, !7, i64 16}


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