; 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 @mergeHeaps(ptr noundef, ptr noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local ptr @unionHeaps(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = call ptr @mergeHeaps(ptr noundef %11, ptr noundef %12)
  store ptr %13, ptr %6, align 8, !tbaa !5
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %17, label %16

16:                                               ; preds = %2
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %87

17:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  store ptr null, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %18, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %19 = load ptr, ptr %9, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.BinomialNode, ptr %19, i32 0, i32 4
  %21 = load ptr, ptr %20, align 8, !tbaa !9
  store ptr %21, ptr %10, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %81, %17
  %23 = load ptr, ptr %10, align 8, !tbaa !5
  %24 = icmp ne ptr %23, null
  br i1 %24, label %25, label %85

25:                                               ; preds = %22
  %26 = load ptr, ptr %9, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.BinomialNode, ptr %26, i32 0, i32 1
  %28 = load i32, ptr %27, align 4, !tbaa !12
  %29 = load ptr, ptr %10, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.BinomialNode, ptr %29, i32 0, i32 1
  %31 = load i32, ptr %30, align 4, !tbaa !12
  %32 = icmp ne i32 %28, %31
  br i1 %32, label %48, label %33

33:                                               ; preds = %25
  %34 = load ptr, ptr %10, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.BinomialNode, ptr %34, i32 0, i32 4
  %36 = load ptr, ptr %35, align 8, !tbaa !9
  %37 = icmp ne ptr %36, null
  br i1 %37, label %38, label %51

38:                                               ; preds = %33
  %39 = load ptr, ptr %10, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.BinomialNode, ptr %39, i32 0, i32 4
  %41 = load ptr, ptr %40, align 8, !tbaa !9
  %42 = getelementptr inbounds %struct.BinomialNode, ptr %41, i32 0, i32 1
  %43 = load i32, ptr %42, align 4, !tbaa !12
  %44 = load ptr, ptr %9, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.BinomialNode, ptr %44, i32 0, i32 1
  %46 = load i32, ptr %45, align 4, !tbaa !12
  %47 = icmp eq i32 %43, %46
  br i1 %47, label %48, label %51

48:                                               ; preds = %38, %25
  %49 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %49, ptr %8, align 8, !tbaa !5
  %50 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %50, ptr %9, align 8, !tbaa !5
  br label %81

51:                                               ; preds = %38, %33
  %52 = load ptr, ptr %9, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.BinomialNode, ptr %52, i32 0, i32 0
  %54 = load i32, ptr %53, align 8, !tbaa !13
  %55 = load ptr, ptr %10, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.BinomialNode, ptr %55, i32 0, i32 0
  %57 = load i32, ptr %56, align 8, !tbaa !13
  %58 = icmp sle i32 %54, %57
  br i1 %58, label %59, label %67

59:                                               ; preds = %51
  %60 = load ptr, ptr %10, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.BinomialNode, ptr %60, i32 0, i32 4
  %62 = load ptr, ptr %61, align 8, !tbaa !9
  %63 = load ptr, ptr %9, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.BinomialNode, ptr %63, i32 0, i32 4
  store ptr %62, ptr %64, align 8, !tbaa !9
  %65 = load ptr, ptr %10, align 8, !tbaa !5
  %66 = load ptr, ptr %9, align 8, !tbaa !5
  call void @linkTrees(ptr noundef %65, ptr noundef %66)
  br label %80

67:                                               ; preds = %51
  %68 = load ptr, ptr %8, align 8, !tbaa !5
  %69 = icmp ne ptr %68, null
  br i1 %69, label %70, label %74

70:                                               ; preds = %67
  %71 = load ptr, ptr %10, align 8, !tbaa !5
  %72 = load ptr, ptr %8, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.BinomialNode, ptr %72, i32 0, i32 4
  store ptr %71, ptr %73, align 8, !tbaa !9
  br label %76

74:                                               ; preds = %67
  %75 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %75, ptr %6, align 8, !tbaa !5
  br label %76

76:                                               ; preds = %74, %70
  %77 = load ptr, ptr %9, align 8, !tbaa !5
  %78 = load ptr, ptr %10, align 8, !tbaa !5
  call void @linkTrees(ptr noundef %77, ptr noundef %78)
  %79 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %79, ptr %9, align 8, !tbaa !5
  br label %80

80:                                               ; preds = %76, %59
  br label %81

81:                                               ; preds = %80, %48
  %82 = load ptr, ptr %9, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.BinomialNode, ptr %82, i32 0, i32 4
  %84 = load ptr, ptr %83, align 8, !tbaa !9
  store ptr %84, ptr %10, align 8, !tbaa !5
  br label %22, !llvm.loop !14

85:                                               ; preds = %22
  %86 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %86, ptr %3, align 8
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  br label %87

87:                                               ; preds = %85, %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  %88 = load ptr, ptr %3, align 8
  ret ptr %88
}

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 = !{!10, !11, i64 4}
!13 = !{!10, !11, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @unionHeaps(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = tail call ptr @mergeHeaps(ptr noundef %0, ptr noundef %1)
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %2
  %.0.in43 = getelementptr inbounds i8, ptr %3, i64 24
  %.044 = load ptr, ptr %.0.in43, align 8, !tbaa !5
  %.not3845 = icmp eq ptr %.044, null
  br i1 %.not3845, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %23
  %.050 = phi ptr [ %.0, %23 ], [ %.044, %.preheader ]
  %.0.in49 = phi ptr [ %.0.in, %23 ], [ %.0.in43, %.preheader ]
  %.02948 = phi ptr [ %.1, %23 ], [ %3, %.preheader ]
  %.03047 = phi ptr [ %.131, %23 ], [ null, %.preheader ]
  %.03246 = phi ptr [ %.2, %23 ], [ %3, %.preheader ]
  %4 = getelementptr inbounds i8, ptr %.02948, i64 4
  %5 = load i32, ptr %4, align 4, !tbaa !11
  %6 = getelementptr inbounds i8, ptr %.050, i64 4
  %7 = load i32, ptr %6, align 4, !tbaa !11
  %.not39 = icmp eq i32 %5, %7
  br i1 %.not39, label %8, label %23

8:                                                ; preds = %.lr.ph
  %9 = getelementptr inbounds i8, ptr %.050, i64 24
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  %.not40 = icmp eq ptr %10, null
  br i1 %.not40, label %15, label %11

11:                                               ; preds = %8
  %12 = getelementptr inbounds i8, ptr %10, i64 4
  %13 = load i32, ptr %12, align 4, !tbaa !11
  %14 = icmp eq i32 %13, %5
  br i1 %14, label %23, label %15

15:                                               ; preds = %11, %8
  %16 = load i32, ptr %.02948, align 8, !tbaa !12
  %17 = load i32, ptr %.050, align 8, !tbaa !12
  %.not41 = icmp sgt i32 %16, %17
  br i1 %.not41, label %19, label %18

18:                                               ; preds = %15
  store ptr %10, ptr %.0.in49, align 8, !tbaa !5
  tail call void @linkTrees(ptr noundef nonnull %.050, ptr noundef nonnull %.02948)
  br label %23

19:                                               ; preds = %15
  %.not42 = icmp eq ptr %.03047, null
  br i1 %.not42, label %22, label %20

20:                                               ; preds = %19
  %21 = getelementptr inbounds i8, ptr %.03047, i64 24
  store ptr %.050, ptr %21, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %19, %20
  %.133 = phi ptr [ %.03246, %20 ], [ %.050, %19 ]
  tail call void @linkTrees(ptr noundef nonnull %.02948, ptr noundef nonnull %.050)
  br label %23

23:                                               ; preds = %.lr.ph, %11, %18, %22
  %.2 = phi ptr [ %.03246, %18 ], [ %.133, %22 ], [ %.03246, %11 ], [ %.03246, %.lr.ph ]
  %.131 = phi ptr [ %.03047, %18 ], [ %.03047, %22 ], [ %.02948, %11 ], [ %.02948, %.lr.ph ]
  %.1 = phi ptr [ %.02948, %18 ], [ %.050, %22 ], [ %.050, %11 ], [ %.050, %.lr.ph ]
  %.0.in = getelementptr inbounds i8, ptr %.1, i64 24
  %.0 = load ptr, ptr %.0.in, align 8, !tbaa !5
  %.not38 = icmp eq ptr %.0, null
  br i1 %.not38, label %.loopexit, label %.lr.ph, !llvm.loop !13

.loopexit:                                        ; preds = %23, %.preheader, %2
  %.034 = phi ptr [ null, %2 ], [ %3, %.preheader ], [ %.2, %23 ]
  ret ptr %.034
}

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


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