; LLVM IR from AlgoGenesis/C :: Heaps/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.FibonacciHeap = type { ptr, i32 }
%struct.Node = type { i32, i32, ptr, ptr, ptr, ptr, i32 }

; 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: nounwind uwtable
declare dso_local void @consolidate(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @extractMin(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.FibonacciHeap, ptr %6, i32 0, i32 0
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  store ptr %8, ptr %3, align 8, !tbaa !5
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = icmp ne ptr %9, null
  br i1 %10, label %11, label %93

11:                                               ; preds = %1
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.Node, ptr %12, i32 0, i32 3
  %14 = load ptr, ptr %13, align 8, !tbaa !12
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %58

16:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.Node, ptr %17, i32 0, i32 3
  %19 = load ptr, ptr %18, align 8, !tbaa !12
  store ptr %19, ptr %4, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %51, %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.Node, ptr %21, i32 0, i32 4
  %23 = load ptr, ptr %22, align 8, !tbaa !14
  store ptr %23, ptr %5, align 8, !tbaa !5
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.FibonacciHeap, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !9
  %27 = getelementptr inbounds %struct.Node, ptr %26, i32 0, i32 5
  %28 = load ptr, ptr %27, align 8, !tbaa !15
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.Node, ptr %29, i32 0, i32 5
  store ptr %28, ptr %30, align 8, !tbaa !15
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.FibonacciHeap, ptr %31, i32 0, i32 0
  %33 = load ptr, ptr %32, align 8, !tbaa !9
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.Node, ptr %34, i32 0, i32 4
  store ptr %33, ptr %35, align 8, !tbaa !14
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = load ptr, ptr %2, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.FibonacciHeap, ptr %37, i32 0, i32 0
  %39 = load ptr, ptr %38, align 8, !tbaa !9
  %40 = getelementptr inbounds %struct.Node, ptr %39, i32 0, i32 5
  %41 = load ptr, ptr %40, align 8, !tbaa !15
  %42 = getelementptr inbounds %struct.Node, ptr %41, i32 0, i32 4
  store ptr %36, ptr %42, align 8, !tbaa !14
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = load ptr, ptr %2, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.FibonacciHeap, ptr %44, i32 0, i32 0
  %46 = load ptr, ptr %45, align 8, !tbaa !9
  %47 = getelementptr inbounds %struct.Node, ptr %46, i32 0, i32 5
  store ptr %43, ptr %47, align 8, !tbaa !15
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.Node, ptr %48, i32 0, i32 2
  store ptr null, ptr %49, align 8, !tbaa !16
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %50, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  br label %51

51:                                               ; preds = %20
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.Node, ptr %53, i32 0, i32 3
  %55 = load ptr, ptr %54, align 8, !tbaa !12
  %56 = icmp ne ptr %52, %55
  br i1 %56, label %20, label %57, !llvm.loop !17

57:                                               ; preds = %51
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  br label %58

58:                                               ; preds = %57, %11
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.Node, ptr %59, i32 0, i32 5
  %61 = load ptr, ptr %60, align 8, !tbaa !15
  %62 = load ptr, ptr %3, align 8, !tbaa !5
  %63 = icmp eq ptr %61, %62
  br i1 %63, label %64, label %67

64:                                               ; preds = %58
  %65 = load ptr, ptr %2, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.FibonacciHeap, ptr %65, i32 0, i32 0
  store ptr null, ptr %66, align 8, !tbaa !9
  br label %87

67:                                               ; preds = %58
  %68 = load ptr, ptr %3, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.Node, ptr %68, i32 0, i32 4
  %70 = load ptr, ptr %69, align 8, !tbaa !14
  %71 = load ptr, ptr %3, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.Node, ptr %71, i32 0, i32 5
  %73 = load ptr, ptr %72, align 8, !tbaa !15
  %74 = getelementptr inbounds %struct.Node, ptr %73, i32 0, i32 4
  store ptr %70, ptr %74, align 8, !tbaa !14
  %75 = load ptr, ptr %3, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.Node, ptr %75, i32 0, i32 5
  %77 = load ptr, ptr %76, align 8, !tbaa !15
  %78 = load ptr, ptr %3, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.Node, ptr %78, i32 0, i32 4
  %80 = load ptr, ptr %79, align 8, !tbaa !14
  %81 = getelementptr inbounds %struct.Node, ptr %80, i32 0, i32 5
  store ptr %77, ptr %81, align 8, !tbaa !15
  %82 = load ptr, ptr %3, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.Node, ptr %82, i32 0, i32 4
  %84 = load ptr, ptr %83, align 8, !tbaa !14
  %85 = load ptr, ptr %2, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.FibonacciHeap, ptr %85, i32 0, i32 0
  store ptr %84, ptr %86, align 8, !tbaa !9
  br label %87

87:                                               ; preds = %67, %64
  %88 = load ptr, ptr %2, align 8, !tbaa !5
  call void @consolidate(ptr noundef %88)
  %89 = load ptr, ptr %2, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.FibonacciHeap, ptr %89, i32 0, i32 1
  %91 = load i32, ptr %90, align 8, !tbaa !19
  %92 = add nsw i32 %91, -1
  store i32 %92, ptr %90, align 8, !tbaa !19
  br label %93

93:                                               ; preds = %87, %1
  %94 = load ptr, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  ret ptr %94
}

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


; 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: nounwind uwtable
declare dso_local void @consolidate(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @extractMin(ptr noundef %0) local_unnamed_addr #0 {
  %2 = load ptr, ptr %0, align 8, !tbaa !5
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %24, label %3

3:                                                ; preds = %1
  %4 = getelementptr inbounds i8, ptr %2, i64 16
  %5 = load ptr, ptr %4, align 8, !tbaa !11
  %.not32 = icmp eq ptr %5, null
  %.phi.trans.insert = getelementptr inbounds i8, ptr %2, i64 32
  %.pre34 = load ptr, ptr %.phi.trans.insert, align 8, !tbaa !13
  br i1 %.not32, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %3, %.preheader
  %6 = phi ptr [ %.0, %.preheader ], [ %.pre34, %3 ]
  %.0 = phi ptr [ %8, %.preheader ], [ %5, %3 ]
  %7 = getelementptr inbounds i8, ptr %.0, i64 24
  %8 = load ptr, ptr %7, align 8, !tbaa !14
  %9 = getelementptr inbounds i8, ptr %.0, i64 32
  store ptr %6, ptr %9, align 8, !tbaa !13
  store ptr %2, ptr %7, align 8, !tbaa !14
  %10 = load ptr, ptr %.phi.trans.insert, align 8, !tbaa !13
  %11 = getelementptr inbounds i8, ptr %10, i64 24
  store ptr %.0, ptr %11, align 8, !tbaa !14
  store ptr %.0, ptr %.phi.trans.insert, align 8, !tbaa !13
  %12 = getelementptr inbounds i8, ptr %.0, i64 8
  store ptr null, ptr %12, align 8, !tbaa !15
  %.not33 = icmp eq ptr %8, %5
  br i1 %.not33, label %.loopexit, label %.preheader, !llvm.loop !16

.loopexit:                                        ; preds = %.preheader, %3
  %13 = phi ptr [ %.pre34, %3 ], [ %.0, %.preheader ]
  %14 = icmp eq ptr %13, %2
  br i1 %14, label %20, label %15

15:                                               ; preds = %.loopexit
  %16 = getelementptr inbounds i8, ptr %2, i64 24
  %17 = load ptr, ptr %16, align 8, !tbaa !14
  %18 = getelementptr inbounds i8, ptr %13, i64 24
  store ptr %17, ptr %18, align 8, !tbaa !14
  %19 = getelementptr inbounds i8, ptr %17, i64 32
  store ptr %13, ptr %19, align 8, !tbaa !13
  br label %20

20:                                               ; preds = %.loopexit, %15
  %storemerge = phi ptr [ %17, %15 ], [ null, %.loopexit ]
  store ptr %storemerge, ptr %0, align 8, !tbaa !5
  tail call void @consolidate(ptr noundef nonnull %0)
  %21 = getelementptr inbounds i8, ptr %0, i64 8
  %22 = load i32, ptr %21, align 8, !tbaa !18
  %23 = add nsw i32 %22, -1
  store i32 %23, ptr %21, align 8, !tbaa !18
  br label %24

24:                                               ; preds = %20, %1
  ret ptr %2
}

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


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass