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

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

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

declare i32 @__gxx_personality_v0(...)

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

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN7BinHeap10mergeRootsEPS_S0_(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef %1, ptr noundef %2) #2 align 2 personality ptr @__gxx_personality_v0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  %15 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %16 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 32) #6
  invoke void @_ZN7BinNodeC2Ev(ptr noundef nonnull align 8 dereferenceable(32) %16)
          to label %17 unwind label %29

17:                                               ; preds = %3
  store ptr %16, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %18 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %18, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = getelementptr inbounds %class.BinHeap, ptr %19, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !9
  store ptr %21, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = getelementptr inbounds %class.BinHeap, ptr %22, i32 0, i32 0
  %24 = load ptr, ptr %23, align 8, !tbaa !9
  store ptr %24, ptr %13, align 8, !tbaa !5
  %25 = load ptr, ptr %12, align 8, !tbaa !5
  %26 = icmp eq ptr %25, null
  br i1 %26, label %27, label %33

27:                                               ; preds = %17
  %28 = load ptr, ptr %13, align 8, !tbaa !5
  store ptr %28, ptr %4, align 8
  store i32 1, ptr %14, align 4
  br label %108

29:                                               ; preds = %3
  %30 = landingpad { ptr, i32 }
          cleanup
  %31 = extractvalue { ptr, i32 } %30, 0
  store ptr %31, ptr %9, align 8
  %32 = extractvalue { ptr, i32 } %30, 1
  store i32 %32, ptr %10, align 4
  call void @_ZdlPvm(ptr noundef %16, i64 noundef 32) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  br label %110

33:                                               ; preds = %17
  %34 = load ptr, ptr %13, align 8, !tbaa !5
  %35 = icmp eq ptr %34, null
  br i1 %35, label %36, label %38

36:                                               ; preds = %33
  %37 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %37, ptr %4, align 8
  store i32 1, ptr %14, align 4
  br label %108

38:                                               ; preds = %33
  br label %39

39:                                               ; preds = %103, %38
  %40 = load ptr, ptr %12, align 8, !tbaa !5
  %41 = icmp ne ptr %40, null
  br i1 %41, label %45, label %42

42:                                               ; preds = %39
  %43 = load ptr, ptr %13, align 8, !tbaa !5
  %44 = icmp ne ptr %43, null
  br label %45

45:                                               ; preds = %42, %39
  %46 = phi i1 [ true, %39 ], [ %44, %42 ]
  br i1 %46, label %47, label %104

47:                                               ; preds = %45
  %48 = load ptr, ptr %12, align 8, !tbaa !5
  %49 = icmp eq ptr %48, null
  br i1 %49, label %50, label %60

50:                                               ; preds = %47
  %51 = load ptr, ptr %13, align 8, !tbaa !5
  %52 = load ptr, ptr %11, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.BinNode, ptr %52, i32 0, i32 2
  store ptr %51, ptr %53, align 8, !tbaa !11
  %54 = load ptr, ptr %11, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.BinNode, ptr %54, i32 0, i32 2
  %56 = load ptr, ptr %55, align 8, !tbaa !11
  store ptr %56, ptr %11, align 8, !tbaa !5
  %57 = load ptr, ptr %13, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.BinNode, ptr %57, i32 0, i32 2
  %59 = load ptr, ptr %58, align 8, !tbaa !11
  store ptr %59, ptr %13, align 8, !tbaa !5
  br label %103

60:                                               ; preds = %47
  %61 = load ptr, ptr %13, align 8, !tbaa !5
  %62 = icmp eq ptr %61, null
  br i1 %62, label %63, label %73

63:                                               ; preds = %60
  %64 = load ptr, ptr %12, align 8, !tbaa !5
  %65 = load ptr, ptr %11, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.BinNode, ptr %65, i32 0, i32 2
  store ptr %64, ptr %66, align 8, !tbaa !11
  %67 = load ptr, ptr %11, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.BinNode, ptr %67, i32 0, i32 2
  %69 = load ptr, ptr %68, align 8, !tbaa !11
  store ptr %69, ptr %11, align 8, !tbaa !5
  %70 = load ptr, ptr %12, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.BinNode, ptr %70, i32 0, i32 2
  %72 = load ptr, ptr %71, align 8, !tbaa !11
  store ptr %72, ptr %12, align 8, !tbaa !5
  br label %102

73:                                               ; preds = %60
  %74 = load ptr, ptr %12, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.BinNode, ptr %74, i32 0, i32 1
  %76 = load i32, ptr %75, align 4, !tbaa !14
  %77 = load ptr, ptr %13, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.BinNode, ptr %77, i32 0, i32 1
  %79 = load i32, ptr %78, align 4, !tbaa !14
  %80 = icmp slt i32 %76, %79
  br i1 %80, label %81, label %91

81:                                               ; preds = %73
  %82 = load ptr, ptr %12, align 8, !tbaa !5
  %83 = load ptr, ptr %11, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.BinNode, ptr %83, i32 0, i32 2
  store ptr %82, ptr %84, align 8, !tbaa !11
  %85 = load ptr, ptr %11, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.BinNode, ptr %85, i32 0, i32 2
  %87 = load ptr, ptr %86, align 8, !tbaa !11
  store ptr %87, ptr %11, align 8, !tbaa !5
  %88 = load ptr, ptr %12, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.BinNode, ptr %88, i32 0, i32 2
  %90 = load ptr, ptr %89, align 8, !tbaa !11
  store ptr %90, ptr %12, align 8, !tbaa !5
  br label %101

91:                                               ; preds = %73
  %92 = load ptr, ptr %13, align 8, !tbaa !5
  %93 = load ptr, ptr %11, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.BinNode, ptr %93, i32 0, i32 2
  store ptr %92, ptr %94, align 8, !tbaa !11
  %95 = load ptr, ptr %11, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.BinNode, ptr %95, i32 0, i32 2
  %97 = load ptr, ptr %96, align 8, !tbaa !11
  store ptr %97, ptr %11, align 8, !tbaa !5
  %98 = load ptr, ptr %13, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.BinNode, ptr %98, i32 0, i32 2
  %100 = load ptr, ptr %99, align 8, !tbaa !11
  store ptr %100, ptr %13, align 8, !tbaa !5
  br label %101

101:                                              ; preds = %91, %81
  br label %102

102:                                              ; preds = %101, %63
  br label %103

103:                                              ; preds = %102, %50
  br label %39, !llvm.loop !15

104:                                              ; preds = %45
  %105 = load ptr, ptr %8, align 8, !tbaa !5
  %106 = getelementptr inbounds %struct.BinNode, ptr %105, i32 0, i32 2
  %107 = load ptr, ptr %106, align 8, !tbaa !11
  store ptr %107, ptr %4, align 8
  store i32 1, ptr %14, align 4
  br label %108

108:                                              ; preds = %104, %36, %27
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  %109 = load ptr, ptr %4, align 8
  ret ptr %109

110:                                              ; preds = %29
  %111 = load ptr, ptr %9, align 8
  %112 = load i32, ptr %10, align 4
  %113 = insertvalue { ptr, i32 } poison, ptr %111, 0
  %114 = insertvalue { ptr, i32 } %113, i32 %112, 1
  resume { ptr, i32 } %114
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7BinNodeC2Ev(ptr noundef nonnull align 8 dereferenceable(32)) unnamed_addr #4 align 2

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

attributes #0 = { 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 #1 = { 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 #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #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 = !{!"_ZTS7BinHeap", !6, i64 0, !6, i64 8}
!11 = !{!12, !6, i64 8}
!12 = !{!"_ZTS7BinNode", !13, i64 0, !13, i64 4, !6, i64 8, !6, i64 16, !6, i64 24}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !13, i64 4}
!15 = distinct !{!15, !16}
!16 = !{!"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: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) local_unnamed_addr #0

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN7BinHeap10mergeRootsEPS_S0_(ptr nocapture noundef nonnull readnone align 8 dereferenceable(16) %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2) local_unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  %4 = tail call noalias noundef nonnull dereferenceable(32) ptr @_Znwm(i64 noundef 32) #3
  tail call void @_ZN7BinNodeC2Ev(ptr noundef nonnull align 8 dereferenceable(32) %4)
  %5 = load ptr, ptr %1, align 8, !tbaa !5
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = icmp eq ptr %5, null
  br i1 %7, label %41, label %8

8:                                                ; preds = %3
  %9 = icmp eq ptr %6, null
  br i1 %9, label %41, label %.preheader

.preheader:                                       ; preds = %8, %34
  %.041 = phi ptr [ %.1, %34 ], [ %6, %8 ]
  %.03240 = phi ptr [ %.133, %34 ], [ %5, %8 ]
  %.03439 = phi ptr [ %.135, %34 ], [ %4, %8 ]
  %10 = icmp eq ptr %.03240, null
  br i1 %10, label %11, label %15

11:                                               ; preds = %.preheader
  %12 = getelementptr inbounds i8, ptr %.03439, i64 8
  store ptr %.041, ptr %12, align 8, !tbaa !10
  %13 = getelementptr inbounds i8, ptr %.041, i64 8
  %14 = load ptr, ptr %13, align 8, !tbaa !10
  br label %34

15:                                               ; preds = %.preheader
  %16 = icmp eq ptr %.041, null
  br i1 %16, label %17, label %21

17:                                               ; preds = %15
  %18 = getelementptr inbounds i8, ptr %.03439, i64 8
  store ptr %.03240, ptr %18, align 8, !tbaa !10
  %19 = getelementptr inbounds i8, ptr %.03240, i64 8
  %20 = load ptr, ptr %19, align 8, !tbaa !10
  br label %34

21:                                               ; preds = %15
  %22 = getelementptr inbounds i8, ptr %.03240, i64 4
  %23 = load i32, ptr %22, align 4, !tbaa !13
  %24 = getelementptr inbounds i8, ptr %.041, i64 4
  %25 = load i32, ptr %24, align 4, !tbaa !13
  %26 = icmp slt i32 %23, %25
  %27 = getelementptr inbounds i8, ptr %.03439, i64 8
  br i1 %26, label %28, label %31

28:                                               ; preds = %21
  store ptr %.03240, ptr %27, align 8, !tbaa !10
  %29 = getelementptr inbounds i8, ptr %.03240, i64 8
  %30 = load ptr, ptr %29, align 8, !tbaa !10
  br label %34

31:                                               ; preds = %21
  store ptr %.041, ptr %27, align 8, !tbaa !10
  %32 = getelementptr inbounds i8, ptr %.041, i64 8
  %33 = load ptr, ptr %32, align 8, !tbaa !10
  br label %34

34:                                               ; preds = %17, %31, %28, %11
  %.135 = phi ptr [ %.041, %11 ], [ %.03240, %17 ], [ %.03240, %28 ], [ %.041, %31 ]
  %.133 = phi ptr [ null, %11 ], [ %20, %17 ], [ %30, %28 ], [ %.03240, %31 ]
  %.1 = phi ptr [ %14, %11 ], [ null, %17 ], [ %.041, %28 ], [ %33, %31 ]
  %35 = icmp ne ptr %.133, null
  %36 = icmp ne ptr %.1, null
  %37 = select i1 %35, i1 true, i1 %36
  br i1 %37, label %.preheader, label %38, !llvm.loop !14

38:                                               ; preds = %34
  %39 = getelementptr inbounds i8, ptr %4, i64 8
  %40 = load ptr, ptr %39, align 8, !tbaa !10
  br label %41

41:                                               ; preds = %8, %3, %38
  %.036 = phi ptr [ %40, %38 ], [ %6, %3 ], [ %5, %8 ]
  ret ptr %.036
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7BinNodeC2Ev(ptr noundef nonnull align 8 dereferenceable(32)) unnamed_addr #2 align 2

attributes #0 = { 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 #1 = { 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 #2 = { 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 = { builtin allocsize(0) }

!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 = !{!"_ZTS7BinHeap", !7, i64 0, !7, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!11, !7, i64 8}
!11 = !{!"_ZTS7BinNode", !12, i64 0, !12, i64 4, !7, i64 8, !7, i64 16, !7, i64 24}
!12 = !{!"int", !8, i64 0}
!13 = !{!11, !12, i64 4}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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