; LLVM IR from ritikbanger/Hacktoberfest2022-DSA :: 16. Heap/FibonacciHeap.ll (ZN13FibonacciHeap11Extract_MinEP4node)

; 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"

%struct.node = type { i32, i32, ptr, ptr, ptr, ptr, i8, i8 }
%class.FibonacciHeap = type { i32, ptr }

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN13FibonacciHeap11Extract_MinEP4node(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef %1) #1 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
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %12 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %13, ptr %8, align 8, !tbaa !5
  %14 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %14, ptr %6, align 8, !tbaa !5
  %15 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %15, ptr %7, align 8, !tbaa !5
  %16 = load ptr, ptr %8, align 8, !tbaa !5
  %17 = icmp eq ptr %16, null
  br i1 %17, label %18, label %20

18:                                               ; preds = %2
  %19 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %19, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %114

20:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  store ptr null, ptr %10, align 8, !tbaa !5
  %21 = load ptr, ptr %8, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.node, ptr %21, i32 0, i32 3
  %23 = load ptr, ptr %22, align 8, !tbaa !9
  %24 = icmp ne ptr %23, null
  br i1 %24, label %25, label %29

25:                                               ; preds = %20
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.node, ptr %26, i32 0, i32 3
  %28 = load ptr, ptr %27, align 8, !tbaa !9
  store ptr %28, ptr %10, align 8, !tbaa !5
  br label %29

29:                                               ; preds = %25, %20
  %30 = load ptr, ptr %10, align 8, !tbaa !5
  %31 = icmp ne ptr %30, null
  br i1 %31, label %32, label %72

32:                                               ; preds = %29
  %33 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %33, ptr %7, align 8, !tbaa !5
  br label %34

34:                                               ; preds = %67, %32
  %35 = load ptr, ptr %10, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.node, ptr %35, i32 0, i32 5
  %37 = load ptr, ptr %36, align 8, !tbaa !12
  store ptr %37, ptr %11, align 8, !tbaa !5
  %38 = load ptr, ptr %10, align 8, !tbaa !5
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.node, ptr %39, i32 0, i32 4
  %41 = load ptr, ptr %40, align 8, !tbaa !13
  %42 = getelementptr inbounds %struct.node, ptr %41, i32 0, i32 5
  store ptr %38, ptr %42, align 8, !tbaa !12
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = load ptr, ptr %10, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.node, ptr %44, i32 0, i32 5
  store ptr %43, ptr %45, align 8, !tbaa !12
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.node, ptr %46, i32 0, i32 4
  %48 = load ptr, ptr %47, align 8, !tbaa !13
  %49 = load ptr, ptr %10, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.node, ptr %49, i32 0, i32 4
  store ptr %48, ptr %50, align 8, !tbaa !13
  %51 = load ptr, ptr %10, align 8, !tbaa !5
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.node, ptr %52, i32 0, i32 4
  store ptr %51, ptr %53, align 8, !tbaa !13
  %54 = load ptr, ptr %10, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.node, ptr %54, i32 0, i32 0
  %56 = load i32, ptr %55, align 8, !tbaa !14
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.node, ptr %57, i32 0, i32 0
  %59 = load i32, ptr %58, align 8, !tbaa !14
  %60 = icmp slt i32 %56, %59
  br i1 %60, label %61, label %63

61:                                               ; preds = %34
  %62 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %62, ptr %5, align 8, !tbaa !5
  br label %63

63:                                               ; preds = %61, %34
  %64 = load ptr, ptr %10, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.node, ptr %64, i32 0, i32 2
  store ptr null, ptr %65, align 8, !tbaa !15
  %66 = load ptr, ptr %11, align 8, !tbaa !5
  store ptr %66, ptr %10, align 8, !tbaa !5
  br label %67

67:                                               ; preds = %63
  %68 = load ptr, ptr %11, align 8, !tbaa !5
  %69 = load ptr, ptr %7, align 8, !tbaa !5
  %70 = icmp ne ptr %68, %69
  br i1 %70, label %34, label %71, !llvm.loop !16

71:                                               ; preds = %67
  br label %72

72:                                               ; preds = %71, %29
  %73 = load ptr, ptr %8, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.node, ptr %73, i32 0, i32 5
  %75 = load ptr, ptr %74, align 8, !tbaa !12
  %76 = load ptr, ptr %8, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.node, ptr %76, i32 0, i32 4
  %78 = load ptr, ptr %77, align 8, !tbaa !13
  %79 = getelementptr inbounds %struct.node, ptr %78, i32 0, i32 5
  store ptr %75, ptr %79, align 8, !tbaa !12
  %80 = load ptr, ptr %8, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.node, ptr %80, i32 0, i32 4
  %82 = load ptr, ptr %81, align 8, !tbaa !13
  %83 = load ptr, ptr %8, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.node, ptr %83, i32 0, i32 5
  %85 = load ptr, ptr %84, align 8, !tbaa !12
  %86 = getelementptr inbounds %struct.node, ptr %85, i32 0, i32 4
  store ptr %82, ptr %86, align 8, !tbaa !13
  %87 = load ptr, ptr %8, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.node, ptr %87, i32 0, i32 5
  %89 = load ptr, ptr %88, align 8, !tbaa !12
  store ptr %89, ptr %5, align 8, !tbaa !5
  %90 = load ptr, ptr %8, align 8, !tbaa !5
  %91 = load ptr, ptr %8, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.node, ptr %91, i32 0, i32 5
  %93 = load ptr, ptr %92, align 8, !tbaa !12
  %94 = icmp eq ptr %90, %93
  br i1 %94, label %95, label %102

95:                                               ; preds = %72
  %96 = load ptr, ptr %8, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.node, ptr %96, i32 0, i32 3
  %98 = load ptr, ptr %97, align 8, !tbaa !9
  %99 = icmp eq ptr %98, null
  br i1 %99, label %100, label %102

100:                                              ; preds = %95
  %101 = getelementptr inbounds %class.FibonacciHeap, ptr %12, i32 0, i32 1
  store ptr null, ptr %101, align 8, !tbaa !18
  br label %108

102:                                              ; preds = %95, %72
  %103 = load ptr, ptr %8, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.node, ptr %103, i32 0, i32 5
  %105 = load ptr, ptr %104, align 8, !tbaa !12
  store ptr %105, ptr %5, align 8, !tbaa !5
  %106 = load ptr, ptr %5, align 8, !tbaa !5
  %107 = call noundef i32 @_ZN13FibonacciHeap11ConsolidateEP4node(ptr noundef nonnull align 8 dereferenceable(16) %12, ptr noundef %106)
  br label %108

108:                                              ; preds = %102, %100
  %109 = getelementptr inbounds %class.FibonacciHeap, ptr %12, i32 0, i32 0
  %110 = load i32, ptr %109, align 8, !tbaa !20
  %111 = sub nsw i32 %110, 1
  %112 = getelementptr inbounds %class.FibonacciHeap, ptr %12, i32 0, i32 0
  store i32 %111, ptr %112, align 8, !tbaa !20
  %113 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %113, ptr %3, align 8
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  br label %114

114:                                              ; preds = %108, %18
  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
  %115 = load ptr, ptr %3, align 8
  ret ptr %115
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 16}
!10 = !{!"_ZTS4node", !11, i64 0, !11, i64 4, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !7, i64 40, !7, i64 41}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 32}
!13 = !{!10, !6, i64 24}
!14 = !{!10, !11, i64 0}
!15 = !{!10, !6, i64 8}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!19, !6, i64 8}
!19 = !{!"_ZTS13FibonacciHeap", !11, i64 0, !6, i64 8}
!20 = !{!19, !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 uwtable
define dso_local noundef ptr @_ZN13FibonacciHeap11Extract_MinEP4node(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef returned %1) local_unnamed_addr #0 align 2 {
  %3 = icmp eq ptr %1, null
  br i1 %3, label %39, label %4

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %1, i64 16
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %.not.not = icmp eq ptr %6, null
  br i1 %.not.not, label %.thread, label %.preheader.preheader

.preheader.preheader:                             ; preds = %4
  %.pre = load i32, ptr %1, align 8, !tbaa !11
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %.preheader
  %7 = phi i32 [ %16, %.preheader ], [ %.pre, %.preheader.preheader ]
  %.039 = phi ptr [ %spec.select45, %.preheader ], [ %1, %.preheader.preheader ]
  %.1 = phi ptr [ %9, %.preheader ], [ %6, %.preheader.preheader ]
  %8 = getelementptr inbounds i8, ptr %.1, i64 32
  %9 = load ptr, ptr %8, align 8, !tbaa !12
  %10 = getelementptr inbounds i8, ptr %.039, i64 24
  %11 = load ptr, ptr %10, align 8, !tbaa !13
  %12 = getelementptr inbounds i8, ptr %11, i64 32
  store ptr %.1, ptr %12, align 8, !tbaa !12
  store ptr %.039, ptr %8, align 8, !tbaa !12
  %13 = getelementptr inbounds i8, ptr %.1, i64 24
  store ptr %11, ptr %13, align 8, !tbaa !13
  store ptr %.1, ptr %10, align 8, !tbaa !13
  %14 = load i32, ptr %.1, align 8, !tbaa !11
  %15 = icmp slt i32 %14, %7
  %16 = tail call i32 @llvm.smin.i32(i32 %14, i32 %7)
  %spec.select45 = select i1 %15, ptr %.1, ptr %.039
  %17 = getelementptr inbounds i8, ptr %.1, i64 8
  store ptr null, ptr %17, align 8, !tbaa !14
  %.not44 = icmp eq ptr %9, %6
  br i1 %.not44, label %18, label %.preheader, !llvm.loop !15

18:                                               ; preds = %.preheader
  %19 = getelementptr inbounds i8, ptr %1, i64 32
  %20 = load ptr, ptr %19, align 8, !tbaa !12
  %21 = getelementptr inbounds i8, ptr %1, i64 24
  %22 = load ptr, ptr %21, align 8, !tbaa !13
  %23 = getelementptr inbounds i8, ptr %22, i64 32
  store ptr %20, ptr %23, align 8, !tbaa !12
  %24 = getelementptr inbounds i8, ptr %20, i64 24
  store ptr %22, ptr %24, align 8, !tbaa !13
  br label %33

.thread:                                          ; preds = %4
  %25 = getelementptr inbounds i8, ptr %1, i64 32
  %26 = load ptr, ptr %25, align 8, !tbaa !12
  %27 = getelementptr inbounds i8, ptr %1, i64 24
  %28 = load ptr, ptr %27, align 8, !tbaa !13
  %29 = getelementptr inbounds i8, ptr %28, i64 32
  store ptr %26, ptr %29, align 8, !tbaa !12
  %30 = getelementptr inbounds i8, ptr %26, i64 24
  store ptr %28, ptr %30, align 8, !tbaa !13
  %31 = icmp eq ptr %26, %1
  br i1 %31, label %.thread46, label %33

.thread46:                                        ; preds = %.thread
  %32 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr null, ptr %32, align 8, !tbaa !17
  br label %36

33:                                               ; preds = %18, %.thread
  %34 = phi ptr [ %26, %.thread ], [ %20, %18 ]
  %35 = tail call noundef i32 @_ZN13FibonacciHeap11ConsolidateEP4node(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef nonnull %34)
  br label %36

36:                                               ; preds = %33, %.thread46
  %37 = load i32, ptr %0, align 8, !tbaa !19
  %38 = add nsw i32 %37, -1
  store i32 %38, ptr %0, align 8, !tbaa !19
  br label %39

39:                                               ; preds = %2, %36
  ret ptr %1
}

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #1

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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 16}
!6 = !{!"_ZTS4node", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !8, i64 40, !8, i64 41}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!6, !10, i64 32}
!13 = !{!6, !10, i64 24}
!14 = !{!6, !10, i64 8}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!18, !10, i64 8}
!18 = !{!"_ZTS13FibonacciHeap", !7, i64 0, !10, i64 8}
!19 = !{!18, !7, i64 0}


; Effective O3 passes: ConstraintEliminationPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopSimplifyPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass