; LLVM IR from ahampriyanshu/algo-ds-101 :: Data-Structures/Tree/Fibonacci-Heap (Fibonacci-Heap)

; 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.fibanocci_heap = type { i32, ptr, i32, i32 }
%struct._NODE = type { i32, i32, ptr, ptr, ptr, ptr, i8, i8 }

@.str.3 = external hidden unnamed_addr constant [20 x i8], align 1

; 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

declare i32 @printf(ptr noundef, ...) #1

; Function Attrs: nounwind uwtable
declare dso_local void @consolidate(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local ptr @extract_min(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %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
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.fibanocci_heap, ptr %7, i32 0, i32 1
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  %10 = icmp eq ptr %9, null
  br i1 %10, label %11, label %13

11:                                               ; preds = %1
  %12 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  br label %126

13:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.fibanocci_heap, ptr %14, i32 0, i32 1
  %16 = load ptr, ptr %15, align 8, !tbaa !9
  store ptr %16, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %17, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store ptr null, ptr %6, align 8, !tbaa !5
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct._NODE, ptr %18, i32 0, i32 5
  %20 = load ptr, ptr %19, align 8, !tbaa !12
  %21 = icmp ne ptr %20, null
  br i1 %21, label %22, label %78

22:                                               ; preds = %13
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct._NODE, ptr %23, i32 0, i32 5
  %25 = load ptr, ptr %24, align 8, !tbaa !12
  store ptr %25, ptr %6, align 8, !tbaa !5
  br label %26

26:                                               ; preds = %71, %22
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct._NODE, ptr %27, i32 0, i32 3
  %29 = load ptr, ptr %28, align 8, !tbaa !15
  store ptr %29, ptr %5, align 8, !tbaa !5
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.fibanocci_heap, ptr %31, i32 0, i32 1
  %33 = load ptr, ptr %32, align 8, !tbaa !9
  %34 = getelementptr inbounds %struct._NODE, ptr %33, i32 0, i32 2
  %35 = load ptr, ptr %34, align 8, !tbaa !16
  %36 = getelementptr inbounds %struct._NODE, ptr %35, i32 0, i32 3
  store ptr %30, ptr %36, align 8, !tbaa !15
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.fibanocci_heap, ptr %37, i32 0, i32 1
  %39 = load ptr, ptr %38, align 8, !tbaa !9
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct._NODE, ptr %40, i32 0, i32 3
  store ptr %39, ptr %41, align 8, !tbaa !15
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.fibanocci_heap, ptr %42, i32 0, i32 1
  %44 = load ptr, ptr %43, align 8, !tbaa !9
  %45 = getelementptr inbounds %struct._NODE, ptr %44, i32 0, i32 2
  %46 = load ptr, ptr %45, align 8, !tbaa !16
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct._NODE, ptr %47, i32 0, i32 2
  store ptr %46, ptr %48, align 8, !tbaa !16
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.fibanocci_heap, ptr %50, i32 0, i32 1
  %52 = load ptr, ptr %51, align 8, !tbaa !9
  %53 = getelementptr inbounds %struct._NODE, ptr %52, i32 0, i32 2
  store ptr %49, ptr %53, align 8, !tbaa !16
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct._NODE, ptr %54, i32 0, i32 0
  %56 = load i32, ptr %55, align 8, !tbaa !17
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.fibanocci_heap, ptr %57, i32 0, i32 1
  %59 = load ptr, ptr %58, align 8, !tbaa !9
  %60 = getelementptr inbounds %struct._NODE, ptr %59, i32 0, i32 0
  %61 = load i32, ptr %60, align 8, !tbaa !17
  %62 = icmp slt i32 %56, %61
  br i1 %62, label %63, label %67

63:                                               ; preds = %26
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = load ptr, ptr %3, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.fibanocci_heap, ptr %65, i32 0, i32 1
  store ptr %64, ptr %66, align 8, !tbaa !9
  br label %67

67:                                               ; preds = %63, %26
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct._NODE, ptr %68, i32 0, i32 4
  store ptr null, ptr %69, align 8, !tbaa !18
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %70, ptr %6, align 8, !tbaa !5
  br label %71

71:                                               ; preds = %67
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  %73 = load ptr, ptr %4, 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 = icmp ne ptr %72, %75
  br i1 %76, label %26, label %77, !llvm.loop !19

77:                                               ; preds = %71
  br label %78

78:                                               ; preds = %77, %13
  %79 = load ptr, ptr %4, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct._NODE, ptr %79, i32 0, i32 3
  %81 = load ptr, ptr %80, align 8, !tbaa !15
  %82 = load ptr, ptr %4, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct._NODE, ptr %82, i32 0, i32 2
  %84 = load ptr, ptr %83, align 8, !tbaa !16
  %85 = getelementptr inbounds %struct._NODE, ptr %84, i32 0, i32 3
  store ptr %81, ptr %85, align 8, !tbaa !15
  %86 = load ptr, ptr %4, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct._NODE, ptr %86, i32 0, i32 2
  %88 = load ptr, ptr %87, align 8, !tbaa !16
  %89 = load ptr, ptr %4, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct._NODE, ptr %89, i32 0, i32 3
  %91 = load ptr, ptr %90, align 8, !tbaa !15
  %92 = getelementptr inbounds %struct._NODE, ptr %91, i32 0, i32 2
  store ptr %88, ptr %92, align 8, !tbaa !16
  %93 = load ptr, ptr %4, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct._NODE, ptr %93, i32 0, i32 3
  %95 = load ptr, ptr %94, align 8, !tbaa !15
  %96 = load ptr, ptr %3, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.fibanocci_heap, ptr %96, i32 0, i32 1
  store ptr %95, ptr %97, align 8, !tbaa !9
  %98 = load ptr, ptr %4, align 8, !tbaa !5
  %99 = load ptr, ptr %4, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct._NODE, ptr %99, i32 0, i32 3
  %101 = load ptr, ptr %100, align 8, !tbaa !15
  %102 = icmp eq ptr %98, %101
  br i1 %102, label %103, label %111

103:                                              ; preds = %78
  %104 = load ptr, ptr %4, align 8, !tbaa !5
  %105 = getelementptr inbounds %struct._NODE, ptr %104, i32 0, i32 5
  %106 = load ptr, ptr %105, align 8, !tbaa !12
  %107 = icmp eq ptr %106, null
  br i1 %107, label %108, label %111

108:                                              ; preds = %103
  %109 = load ptr, ptr %3, align 8, !tbaa !5
  %110 = getelementptr inbounds %struct.fibanocci_heap, ptr %109, i32 0, i32 1
  store ptr null, ptr %110, align 8, !tbaa !9
  br label %118

111:                                              ; preds = %103, %78
  %112 = load ptr, ptr %4, align 8, !tbaa !5
  %113 = getelementptr inbounds %struct._NODE, ptr %112, i32 0, i32 3
  %114 = load ptr, ptr %113, align 8, !tbaa !15
  %115 = load ptr, ptr %3, align 8, !tbaa !5
  %116 = getelementptr inbounds %struct.fibanocci_heap, ptr %115, i32 0, i32 1
  store ptr %114, ptr %116, align 8, !tbaa !9
  %117 = load ptr, ptr %3, align 8, !tbaa !5
  call void @consolidate(ptr noundef %117)
  br label %118

118:                                              ; preds = %111, %108
  %119 = load ptr, ptr %3, align 8, !tbaa !5
  %120 = getelementptr inbounds %struct.fibanocci_heap, ptr %119, i32 0, i32 0
  %121 = load i32, ptr %120, align 8, !tbaa !21
  %122 = sub nsw i32 %121, 1
  %123 = load ptr, ptr %3, align 8, !tbaa !5
  %124 = getelementptr inbounds %struct.fibanocci_heap, ptr %123, i32 0, i32 0
  store i32 %122, ptr %124, align 8, !tbaa !21
  %125 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %125, ptr %2, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  br label %130

126:                                              ; preds = %11
  %127 = load ptr, ptr %3, align 8, !tbaa !5
  %128 = getelementptr inbounds %struct.fibanocci_heap, ptr %127, i32 0, i32 1
  %129 = load ptr, ptr %128, align 8, !tbaa !9
  store ptr %129, ptr %2, align 8
  br label %130

130:                                              ; preds = %126, %118
  %131 = load ptr, ptr %2, align 8
  ret ptr %131
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 = { 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/C++ TBAA"}
!9 = !{!10, !6, i64 8}
!10 = !{!"fibanocci_heap", !11, i64 0, !6, i64 8, !11, i64 16, !11, i64 20}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !6, i64 32}
!13 = !{!"_NODE", !11, i64 0, !11, i64 4, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !14, i64 40, !14, i64 41}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{!13, !6, i64 16}
!16 = !{!13, !6, i64 8}
!17 = !{!13, !11, i64 0}
!18 = !{!13, !6, i64 24}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!10, !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"

@.str.3 = external hidden unnamed_addr constant [20 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @consolidate(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local ptr @extract_min(ptr noundef %0) local_unnamed_addr #1 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = icmp eq ptr %3, null
  br i1 %4, label %5, label %8

5:                                                ; preds = %1
  %6 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  br label %34

8:                                                ; preds = %1
  %9 = getelementptr inbounds i8, ptr %3, i64 32
  %10 = load ptr, ptr %9, align 8, !tbaa !11
  %.not = icmp ne ptr %10, null
  br i1 %.not, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %8, %.preheader
  %11 = phi ptr [ %spec.select, %.preheader ], [ %3, %8 ]
  %.0 = phi ptr [ %13, %.preheader ], [ %10, %8 ]
  %12 = getelementptr inbounds i8, ptr %.0, i64 16
  %13 = load ptr, ptr %12, align 8, !tbaa !14
  %14 = getelementptr inbounds i8, ptr %11, i64 8
  %15 = load ptr, ptr %14, align 8, !tbaa !15
  %16 = getelementptr inbounds i8, ptr %15, i64 16
  store ptr %.0, ptr %16, align 8, !tbaa !14
  store ptr %11, ptr %12, align 8, !tbaa !14
  %17 = getelementptr inbounds i8, ptr %.0, i64 8
  store ptr %15, ptr %17, align 8, !tbaa !15
  store ptr %.0, ptr %14, align 8, !tbaa !15
  %18 = load i32, ptr %.0, align 8, !tbaa !16
  %19 = load i32, ptr %11, align 8, !tbaa !16
  %20 = icmp slt i32 %18, %19
  %spec.select = select i1 %20, ptr %.0, ptr %11
  %21 = getelementptr inbounds i8, ptr %.0, i64 24
  store ptr null, ptr %21, align 8, !tbaa !17
  %.not44 = icmp eq ptr %13, %10
  br i1 %.not44, label %.loopexit, label %.preheader, !llvm.loop !18

.loopexit:                                        ; preds = %.preheader, %8
  %22 = getelementptr inbounds i8, ptr %3, i64 16
  %23 = load ptr, ptr %22, align 8, !tbaa !14
  %24 = getelementptr inbounds i8, ptr %3, i64 8
  %25 = load ptr, ptr %24, align 8, !tbaa !15
  %26 = getelementptr inbounds i8, ptr %25, i64 16
  store ptr %23, ptr %26, align 8, !tbaa !14
  %27 = getelementptr inbounds i8, ptr %23, i64 8
  store ptr %25, ptr %27, align 8, !tbaa !15
  %28 = icmp ne ptr %3, %23
  %brmerge = or i1 %.not, %28
  br i1 %brmerge, label %30, label %29

29:                                               ; preds = %.loopexit
  store ptr null, ptr %2, align 8, !tbaa !5
  br label %31

30:                                               ; preds = %.loopexit
  store ptr %23, ptr %2, align 8, !tbaa !5
  tail call void @consolidate(ptr noundef nonnull %0)
  br label %31

31:                                               ; preds = %30, %29
  %32 = load i32, ptr %0, align 8, !tbaa !20
  %33 = add nsw i32 %32, -1
  store i32 %33, ptr %0, align 8, !tbaa !20
  br label %34

34:                                               ; preds = %5, %31
  %.040 = phi ptr [ %7, %5 ], [ %3, %31 ]
  ret ptr %.040
}

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


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass