; LLVM IR from AlgoGenesis/C :: Heaps/Binomial Heap (binomial-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.BinomialNode = type { i32, i32, ptr, ptr, 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: nounwind uwtable
declare dso_local ptr @unionHeaps(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @findMin(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
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = load ptr, ptr %10, align 8, !tbaa !5
  %12 = icmp ne ptr %11, null
  br i1 %12, label %14, label %13

13:                                               ; preds = %1
  store ptr null, ptr %2, align 8
  br label %74

14:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = load ptr, ptr %15, align 8, !tbaa !5
  %17 = call ptr @findMin(ptr noundef %16)
  store ptr %17, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  store ptr null, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = load ptr, ptr %18, align 8, !tbaa !5
  store ptr %19, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  store ptr null, ptr %7, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %33, %14
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.BinomialNode, ptr %21, i32 0, i32 4
  %23 = load ptr, ptr %22, align 8, !tbaa !9
  %24 = icmp ne ptr %23, null
  br i1 %24, label %25, label %37

25:                                               ; preds = %20
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.BinomialNode, ptr %26, i32 0, i32 4
  %28 = load ptr, ptr %27, align 8, !tbaa !9
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = icmp eq ptr %28, %29
  br i1 %30, label %31, label %33

31:                                               ; preds = %25
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %32, ptr %5, align 8, !tbaa !5
  br label %37

33:                                               ; preds = %25
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.BinomialNode, ptr %34, i32 0, i32 4
  %36 = load ptr, ptr %35, align 8, !tbaa !9
  store ptr %36, ptr %6, align 8, !tbaa !5
  br label %20, !llvm.loop !12

37:                                               ; preds = %31, %20
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = icmp ne ptr %38, null
  br i1 %39, label %40, label %46

40:                                               ; preds = %37
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.BinomialNode, ptr %41, i32 0, i32 4
  %43 = load ptr, ptr %42, align 8, !tbaa !9
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.BinomialNode, ptr %44, i32 0, i32 4
  store ptr %43, ptr %45, align 8, !tbaa !9
  br label %51

46:                                               ; preds = %37
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.BinomialNode, ptr %47, i32 0, i32 4
  %49 = load ptr, ptr %48, align 8, !tbaa !9
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %49, ptr %50, align 8, !tbaa !5
  br label %51

51:                                               ; preds = %46, %40
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.BinomialNode, ptr %52, i32 0, i32 3
  %54 = load ptr, ptr %53, align 8, !tbaa !14
  store ptr %54, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  store ptr null, ptr %9, align 8, !tbaa !5
  br label %55

55:                                               ; preds = %58, %51
  %56 = load ptr, ptr %8, align 8, !tbaa !5
  %57 = icmp ne ptr %56, null
  br i1 %57, label %58, label %67

58:                                               ; preds = %55
  %59 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %59, ptr %9, align 8, !tbaa !5
  %60 = load ptr, ptr %8, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.BinomialNode, ptr %60, i32 0, i32 4
  %62 = load ptr, ptr %61, align 8, !tbaa !9
  store ptr %62, ptr %8, align 8, !tbaa !5
  %63 = load ptr, ptr %9, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.BinomialNode, ptr %63, i32 0, i32 4
  store ptr null, ptr %64, align 8, !tbaa !9
  %65 = load ptr, ptr %9, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.BinomialNode, ptr %65, i32 0, i32 2
  store ptr null, ptr %66, align 8, !tbaa !15
  br label %55, !llvm.loop !16

67:                                               ; preds = %55
  %68 = load ptr, ptr %3, align 8, !tbaa !5
  %69 = load ptr, ptr %68, align 8, !tbaa !5
  %70 = load ptr, ptr %9, align 8, !tbaa !5
  %71 = call ptr @unionHeaps(ptr noundef %69, ptr noundef %70)
  %72 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %71, ptr %72, align 8, !tbaa !5
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %73, ptr %2, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  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
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  br label %74

74:                                               ; preds = %67, %13
  %75 = load ptr, ptr %2, align 8
  ret ptr %75
}

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 24}
!10 = !{!"BinomialNode", !11, i64 0, !11, i64 4, !6, i64 8, !6, i64 16, !6, i64 24}
!11 = !{!"int", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!10, !6, i64 16}
!15 = !{!10, !6, i64 8}
!16 = distinct !{!16, !13}


; 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 ptr @unionHeaps(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @findMin(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @extractMin(ptr nocapture 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 %22, label %3

3:                                                ; preds = %1
  %4 = tail call ptr @findMin(ptr noundef nonnull %2)
  %5 = load ptr, ptr %0, align 8, !tbaa !5
  br label %6

6:                                                ; preds = %9, %3
  %.026 = phi ptr [ %5, %3 ], [ %8, %9 ]
  %7 = getelementptr inbounds i8, ptr %.026, i64 24
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  %.not30 = icmp eq ptr %8, null
  br i1 %.not30, label %.loopexit, label %9

9:                                                ; preds = %6
  %10 = icmp eq ptr %8, %4
  br i1 %10, label %11, label %6, !llvm.loop !12

11:                                               ; preds = %9
  %12 = getelementptr inbounds i8, ptr %.026, i64 24
  br label %.loopexit

.loopexit:                                        ; preds = %6, %11
  %.sink40 = phi ptr [ %12, %11 ], [ %0, %6 ]
  %13 = getelementptr inbounds i8, ptr %4, i64 24
  %14 = load ptr, ptr %13, align 8, !tbaa !9
  store ptr %14, ptr %.sink40, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %4, i64 16
  %16 = load ptr, ptr %15, align 8, !tbaa !14
  %.not3236 = icmp eq ptr %16, null
  br i1 %.not3236, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.loopexit, %.lr.ph
  %.02437 = phi ptr [ %18, %.lr.ph ], [ %16, %.loopexit ]
  %17 = getelementptr inbounds i8, ptr %.02437, i64 24
  %18 = load ptr, ptr %17, align 8, !tbaa !9
  store ptr null, ptr %17, align 8, !tbaa !9
  %19 = getelementptr inbounds i8, ptr %.02437, i64 8
  store ptr null, ptr %19, align 8, !tbaa !15
  %.not32 = icmp eq ptr %18, null
  br i1 %.not32, label %._crit_edge, label %.lr.ph, !llvm.loop !16

._crit_edge:                                      ; preds = %.lr.ph, %.loopexit
  %.0.lcssa = phi ptr [ null, %.loopexit ], [ %.02437, %.lr.ph ]
  %20 = load ptr, ptr %0, align 8, !tbaa !5
  %21 = tail call ptr @unionHeaps(ptr noundef %20, ptr noundef %.0.lcssa)
  store ptr %21, ptr %0, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %1, %._crit_edge
  %.025 = phi ptr [ %4, %._crit_edge ], [ null, %1 ]
  ret ptr %.025
}

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


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