; LLVM IR from maksimandrianov/cdcontainers :: src (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.cdc_binomial_heap_node = type { ptr, ptr, ptr, i64, ptr }
%struct.cdc_binomial_heap = type { ptr, ptr, i64, ptr }
%struct.cdc_data_info = type { ptr, ptr, ptr, ptr, ptr, i64, i64 }

@.str = external hidden unnamed_addr constant [10 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [82 x i8], align 1
@__PRETTY_FUNCTION__.cdc_binomial_heap_extract_top = external hidden unnamed_addr constant [63 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @cdc_binomial_heap_extract_top(ptr noundef %0) #2 {
  %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
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = icmp ne ptr %6, null
  br i1 %7, label %8, label %9

8:                                                ; preds = %1
  br label %10

9:                                                ; preds = %1
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 308, ptr noundef @__PRETTY_FUNCTION__.cdc_binomial_heap_extract_top) #3
  unreachable

10:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  store ptr null, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = call ptr @find_prev_top(ptr noundef %11)
  store ptr %12, ptr %4, align 8, !tbaa !5
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %24

15:                                               ; preds = %10
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.cdc_binomial_heap_node, ptr %16, i32 0, i32 2
  %18 = load ptr, ptr %17, align 8, !tbaa !9
  store ptr %18, ptr %3, align 8, !tbaa !5
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.cdc_binomial_heap_node, ptr %19, i32 0, i32 2
  %21 = load ptr, ptr %20, align 8, !tbaa !9
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.cdc_binomial_heap_node, ptr %22, i32 0, i32 2
  store ptr %21, ptr %23, align 8, !tbaa !9
  br label %33

24:                                               ; preds = %10
  %25 = load ptr, ptr %2, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.cdc_binomial_heap, ptr %25, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !12
  store ptr %27, ptr %3, align 8, !tbaa !5
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.cdc_binomial_heap_node, ptr %28, i32 0, i32 2
  %30 = load ptr, ptr %29, align 8, !tbaa !9
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.cdc_binomial_heap, ptr %31, i32 0, i32 0
  store ptr %30, ptr %32, align 8, !tbaa !12
  br label %33

33:                                               ; preds = %24, %15
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.cdc_binomial_heap_node, ptr %34, i32 0, i32 1
  %36 = load ptr, ptr %35, align 8, !tbaa !14
  store ptr %36, ptr %5, align 8, !tbaa !5
  %37 = load ptr, ptr %2, align 8, !tbaa !5
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  call void @free_node(ptr noundef %37, ptr noundef %38)
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %39, ptr %3, align 8, !tbaa !5
  br label %40

40:                                               ; preds = %43, %33
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = icmp ne ptr %41, null
  br i1 %42, label %43, label %49

43:                                               ; preds = %40
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.cdc_binomial_heap_node, ptr %44, i32 0, i32 0
  store ptr null, ptr %45, align 8, !tbaa !15
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.cdc_binomial_heap_node, ptr %46, i32 0, i32 2
  %48 = load ptr, ptr %47, align 8, !tbaa !9
  store ptr %48, ptr %3, align 8, !tbaa !5
  br label %40, !llvm.loop !16

49:                                               ; preds = %40
  %50 = load ptr, ptr %2, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.cdc_binomial_heap, ptr %50, i32 0, i32 0
  %52 = load ptr, ptr %51, align 8, !tbaa !12
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = load ptr, ptr %2, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.cdc_binomial_heap, ptr %54, i32 0, i32 3
  %56 = load ptr, ptr %55, align 8, !tbaa !18
  %57 = getelementptr inbounds %struct.cdc_data_info, ptr %56, i32 0, i32 1
  %58 = load ptr, ptr %57, align 8, !tbaa !19
  %59 = call ptr @meld(ptr noundef %52, ptr noundef %53, ptr noundef %58)
  %60 = load ptr, ptr %2, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.cdc_binomial_heap, ptr %60, i32 0, i32 0
  store ptr %59, ptr %61, align 8, !tbaa !12
  %62 = load ptr, ptr %2, align 8, !tbaa !5
  %63 = call ptr @find_top(ptr noundef %62)
  %64 = load ptr, ptr %2, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.cdc_binomial_heap, ptr %64, i32 0, i32 1
  store ptr %63, ptr %65, align 8, !tbaa !21
  %66 = load ptr, ptr %2, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.cdc_binomial_heap, ptr %66, i32 0, i32 2
  %68 = load i64, ptr %67, align 8, !tbaa !22
  %69 = add i64 %68, -1
  store i64 %69, ptr %67, align 8, !tbaa !22
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret i32 0
}

; Function Attrs: nounwind uwtable
declare hidden ptr @find_prev_top(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden void @free_node(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden ptr @meld(ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden ptr @find_top(ptr noundef) #2

attributes #0 = { noreturn 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { noreturn nounwind }
attributes #4 = { 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 16}
!10 = !{!"cdc_binomial_heap_node", !6, i64 0, !6, i64 8, !6, i64 16, !11, i64 24, !6, i64 32}
!11 = !{!"long", !7, i64 0}
!12 = !{!13, !6, i64 0}
!13 = !{!"cdc_binomial_heap", !6, i64 0, !6, i64 8, !11, i64 16, !6, i64 24}
!14 = !{!10, !6, i64 8}
!15 = !{!10, !6, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!13, !6, i64 24}
!19 = !{!20, !6, i64 8}
!20 = !{!"cdc_data_info", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !11, i64 40, !11, i64 48}
!21 = !{!13, !6, i64 8}
!22 = !{!13, !11, i64 16}


; 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 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [82 x i8], align 1
@__PRETTY_FUNCTION__.cdc_binomial_heap_extract_top = external hidden unnamed_addr constant [63 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @cdc_binomial_heap_extract_top(ptr noundef %0) local_unnamed_addr #1 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %2, label %3

2:                                                ; preds = %1
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 308, ptr noundef nonnull @__PRETTY_FUNCTION__.cdc_binomial_heap_extract_top) #2
  unreachable

3:                                                ; preds = %1
  %4 = tail call ptr @find_prev_top(ptr noundef nonnull %0)
  %.not25 = icmp eq ptr %4, null
  %5 = getelementptr inbounds i8, ptr %4, i64 16
  %.sink31 = select i1 %.not25, ptr %0, ptr %5
  %6 = load ptr, ptr %.sink31, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %6, i64 16
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  store ptr %8, ptr %.sink31, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %6, i64 8
  %10 = load ptr, ptr %9, align 8, !tbaa !12
  tail call void @free_node(ptr noundef nonnull %0, ptr noundef nonnull %6)
  %.not2627 = icmp eq ptr %10, null
  br i1 %.not2627, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3, %.lr.ph
  %.128 = phi ptr [ %12, %.lr.ph ], [ %10, %3 ]
  store ptr null, ptr %.128, align 8, !tbaa !13
  %11 = getelementptr inbounds i8, ptr %.128, i64 16
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  %.not26 = icmp eq ptr %12, null
  br i1 %.not26, label %._crit_edge, label %.lr.ph, !llvm.loop !14

._crit_edge:                                      ; preds = %.lr.ph, %3
  %13 = load ptr, ptr %0, align 8, !tbaa !16
  %14 = getelementptr inbounds i8, ptr %0, i64 24
  %15 = load ptr, ptr %14, align 8, !tbaa !18
  %16 = getelementptr inbounds i8, ptr %15, i64 8
  %17 = load ptr, ptr %16, align 8, !tbaa !19
  %18 = tail call ptr @meld(ptr noundef %13, ptr noundef %10, ptr noundef %17)
  store ptr %18, ptr %0, align 8, !tbaa !16
  %19 = tail call ptr @find_top(ptr noundef nonnull %0)
  %20 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %19, ptr %20, align 8, !tbaa !21
  %21 = getelementptr inbounds i8, ptr %0, i64 16
  %22 = load i64, ptr %21, align 8, !tbaa !22
  %23 = add i64 %22, -1
  store i64 %23, ptr %21, align 8, !tbaa !22
  ret i32 0
}

; Function Attrs: nounwind uwtable
declare hidden ptr @find_prev_top(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden void @free_node(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden ptr @meld(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden ptr @find_top(ptr noundef) local_unnamed_addr #1

attributes #0 = { noreturn 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" }
attributes #2 = { noreturn 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 16}
!10 = !{!"cdc_binomial_heap_node", !6, i64 0, !6, i64 8, !6, i64 16, !11, i64 24, !6, i64 32}
!11 = !{!"long", !7, i64 0}
!12 = !{!10, !6, i64 8}
!13 = !{!10, !6, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!17, !6, i64 0}
!17 = !{!"cdc_binomial_heap", !6, i64 0, !6, i64 8, !11, i64 16, !6, i64 24}
!18 = !{!17, !6, i64 24}
!19 = !{!20, !6, i64 8}
!20 = !{!"cdc_data_info", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !11, i64 40, !11, i64 48}
!21 = !{!17, !6, i64 8}
!22 = !{!17, !11, i64 16}


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