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

; 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.FibHeap = type <{ ptr, i32, [4 x i8] }>
%struct.FibNode = type { i32, i8, i32, ptr, ptr, ptr, ptr }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN7FibHeap7isEmptyEv(ptr noundef nonnull align 8 dereferenceable(12)) #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN7FibHeap5mergeEPS_(ptr noundef nonnull align 8 dereferenceable(12) %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
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %9 = load ptr, ptr %3, align 8
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %class.FibHeap, ptr %10, i32 0, i32 1
  %12 = load i32, ptr %11, align 8, !tbaa !9
  %13 = getelementptr inbounds %class.FibHeap, ptr %9, i32 0, i32 1
  %14 = load i32, ptr %13, align 8, !tbaa !9
  %15 = add nsw i32 %14, %12
  store i32 %15, ptr %13, align 8, !tbaa !9
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = call noundef zeroext i1 @_ZN7FibHeap7isEmptyEv(ptr noundef nonnull align 8 dereferenceable(12) %16)
  br i1 %17, label %18, label %19

18:                                               ; preds = %2
  br label %69

19:                                               ; preds = %2
  %20 = call noundef zeroext i1 @_ZN7FibHeap7isEmptyEv(ptr noundef nonnull align 8 dereferenceable(12) %9)
  br i1 %20, label %21, label %26

21:                                               ; preds = %19
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %class.FibHeap, ptr %22, i32 0, i32 0
  %24 = load ptr, ptr %23, align 8, !tbaa !12
  %25 = getelementptr inbounds %class.FibHeap, ptr %9, i32 0, i32 0
  store ptr %24, ptr %25, align 8, !tbaa !12
  br label %69

26:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %27 = getelementptr inbounds %class.FibHeap, ptr %9, i32 0, i32 0
  %28 = load ptr, ptr %27, align 8, !tbaa !12
  store ptr %28, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %29 = getelementptr inbounds %class.FibHeap, ptr %9, i32 0, i32 0
  %30 = load ptr, ptr %29, align 8, !tbaa !12
  %31 = getelementptr inbounds %struct.FibNode, ptr %30, i32 0, i32 3
  %32 = load ptr, ptr %31, align 8, !tbaa !13
  store ptr %32, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %class.FibHeap, ptr %33, i32 0, i32 0
  %35 = load ptr, ptr %34, align 8, !tbaa !12
  store ptr %35, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %class.FibHeap, ptr %36, i32 0, i32 0
  %38 = load ptr, ptr %37, align 8, !tbaa !12
  %39 = getelementptr inbounds %struct.FibNode, ptr %38, i32 0, i32 3
  %40 = load ptr, ptr %39, align 8, !tbaa !13
  store ptr %40, ptr %8, align 8, !tbaa !5
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.FibNode, ptr %42, i32 0, i32 3
  store ptr %41, ptr %43, align 8, !tbaa !13
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.FibNode, ptr %45, i32 0, i32 4
  store ptr %44, ptr %46, align 8, !tbaa !16
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.FibNode, ptr %48, i32 0, i32 3
  store ptr %47, ptr %49, align 8, !tbaa !13
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.FibNode, ptr %51, i32 0, i32 4
  store ptr %50, ptr %52, align 8, !tbaa !16
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds %class.FibHeap, ptr %53, i32 0, i32 0
  %55 = load ptr, ptr %54, align 8, !tbaa !12
  %56 = getelementptr inbounds %struct.FibNode, ptr %55, i32 0, i32 0
  %57 = load i32, ptr %56, align 8, !tbaa !17
  %58 = getelementptr inbounds %class.FibHeap, ptr %9, i32 0, i32 0
  %59 = load ptr, ptr %58, align 8, !tbaa !12
  %60 = getelementptr inbounds %struct.FibNode, ptr %59, i32 0, i32 0
  %61 = load i32, ptr %60, align 8, !tbaa !17
  %62 = icmp slt i32 %57, %61
  br i1 %62, label %63, label %68

63:                                               ; preds = %26
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = getelementptr inbounds %class.FibHeap, ptr %64, i32 0, i32 0
  %66 = load ptr, ptr %65, align 8, !tbaa !12
  %67 = getelementptr inbounds %class.FibHeap, ptr %9, i32 0, i32 0
  store ptr %66, ptr %67, align 8, !tbaa !12
  br label %68

68:                                               ; preds = %63, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  br label %69

69:                                               ; preds = %68, %21, %18
  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, !11, i64 8}
!10 = !{!"_ZTS7FibHeap", !6, i64 0, !11, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 0}
!13 = !{!14, !6, i64 16}
!14 = !{!"_ZTS7FibNode", !11, i64 0, !15, i64 4, !11, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!15 = !{!"bool", !7, i64 0}
!16 = !{!14, !6, i64 24}
!17 = !{!14, !11, i64 0}


; 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 @_ZN7FibHeap7isEmptyEv(ptr noundef nonnull align 8 dereferenceable(12)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN7FibHeap5mergeEPS_(ptr noundef nonnull align 8 dereferenceable(12) %0, ptr noundef nonnull %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %1, i64 8
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load i32, ptr %5, align 8, !tbaa !5
  %7 = add nsw i32 %6, %4
  store i32 %7, ptr %5, align 8, !tbaa !5
  %8 = tail call noundef zeroext i1 @_ZN7FibHeap7isEmptyEv(ptr noundef nonnull align 8 dereferenceable(12) %1)
  br i1 %8, label %25, label %9

9:                                                ; preds = %2
  %10 = tail call noundef zeroext i1 @_ZN7FibHeap7isEmptyEv(ptr noundef nonnull align 8 dereferenceable(12) %0)
  br i1 %10, label %11, label %13

11:                                               ; preds = %9
  %12 = load ptr, ptr %1, align 8, !tbaa !11
  br label %.sink.split

13:                                               ; preds = %9
  %14 = load ptr, ptr %0, align 8, !tbaa !11
  %15 = getelementptr inbounds i8, ptr %14, i64 16
  %16 = load ptr, ptr %15, align 8, !tbaa !12
  %17 = load ptr, ptr %1, align 8, !tbaa !11
  %18 = getelementptr inbounds i8, ptr %17, i64 16
  %19 = load ptr, ptr %18, align 8, !tbaa !12
  store ptr %19, ptr %15, align 8, !tbaa !12
  %20 = getelementptr inbounds i8, ptr %16, i64 24
  store ptr %17, ptr %20, align 8, !tbaa !15
  store ptr %16, ptr %18, align 8, !tbaa !12
  %21 = getelementptr inbounds i8, ptr %19, i64 24
  store ptr %14, ptr %21, align 8, !tbaa !15
  %22 = load i32, ptr %17, align 8, !tbaa !16
  %23 = load i32, ptr %14, align 8, !tbaa !16
  %24 = icmp slt i32 %22, %23
  br i1 %24, label %.sink.split, label %25

.sink.split:                                      ; preds = %13, %11
  %.sink = phi ptr [ %12, %11 ], [ %17, %13 ]
  store ptr %.sink, ptr %0, align 8, !tbaa !11
  br label %25

25:                                               ; preds = %.sink.split, %13, %2
  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, !10, i64 8}
!6 = !{!"_ZTS7FibHeap", !7, i64 0, !10, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!13, !7, i64 16}
!13 = !{!"_ZTS7FibNode", !10, i64 0, !14, i64 4, !10, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40}
!14 = !{!"bool", !8, i64 0}
!15 = !{!13, !7, i64 24}
!16 = !{!13, !10, i64 0}


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