; LLVM IR from openssl/openssl :: ssl (priority_queue)

; 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.ossl_pqueue_st = type { ptr, ptr, ptr, i64, i64, i64 }
%struct.pq_elem_st = type { i64, i32 }
%struct.pq_heap_st = type { ptr, i64 }

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

14:                                               ; preds = %3
  store i32 0, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %67

15:                                               ; preds = %3
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.ossl_pqueue_st, ptr %16, i32 0, i32 3
  %18 = load i64, ptr %17, align 8, !tbaa !9
  %19 = add i64 %18, 1
  store i64 %19, ptr %17, align 8, !tbaa !9
  store i64 %18, ptr %8, align 8, !tbaa !12
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.ossl_pqueue_st, ptr %20, i32 0, i32 5
  %22 = load i64, ptr %21, align 8, !tbaa !13
  store i64 %22, ptr %9, align 8, !tbaa !12
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.ossl_pqueue_st, ptr %23, i32 0, i32 1
  %25 = load ptr, ptr %24, align 8, !tbaa !14
  %26 = load i64, ptr %9, align 8, !tbaa !12
  %27 = getelementptr inbounds %struct.pq_elem_st, ptr %25, i64 %26
  %28 = getelementptr inbounds %struct.pq_elem_st, ptr %27, i32 0, i32 0
  %29 = load i64, ptr %28, align 8, !tbaa !15
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.ossl_pqueue_st, ptr %30, i32 0, i32 5
  store i64 %29, ptr %31, align 8, !tbaa !13
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.ossl_pqueue_st, ptr %33, i32 0, i32 0
  %35 = load ptr, ptr %34, align 8, !tbaa !18
  %36 = load i64, ptr %8, align 8, !tbaa !12
  %37 = getelementptr inbounds %struct.pq_heap_st, ptr %35, i64 %36
  %38 = getelementptr inbounds %struct.pq_heap_st, ptr %37, i32 0, i32 0
  store ptr %32, ptr %38, align 8, !tbaa !19
  %39 = load i64, ptr %9, align 8, !tbaa !12
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.ossl_pqueue_st, ptr %40, i32 0, i32 0
  %42 = load ptr, ptr %41, align 8, !tbaa !18
  %43 = load i64, ptr %8, align 8, !tbaa !12
  %44 = getelementptr inbounds %struct.pq_heap_st, ptr %42, i64 %43
  %45 = getelementptr inbounds %struct.pq_heap_st, ptr %44, i32 0, i32 1
  store i64 %39, ptr %45, align 8, !tbaa !21
  %46 = load i64, ptr %8, align 8, !tbaa !12
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.ossl_pqueue_st, ptr %47, i32 0, i32 1
  %49 = load ptr, ptr %48, align 8, !tbaa !14
  %50 = load i64, ptr %9, align 8, !tbaa !12
  %51 = getelementptr inbounds %struct.pq_elem_st, ptr %49, i64 %50
  %52 = getelementptr inbounds %struct.pq_elem_st, ptr %51, i32 0, i32 0
  store i64 %46, ptr %52, align 8, !tbaa !15
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.ossl_pqueue_st, ptr %53, i32 0, i32 1
  %55 = load ptr, ptr %54, align 8, !tbaa !14
  %56 = load i64, ptr %9, align 8, !tbaa !12
  %57 = getelementptr inbounds %struct.pq_elem_st, ptr %55, i64 %56
  %58 = getelementptr inbounds %struct.pq_elem_st, ptr %57, i32 0, i32 1
  store i32 1, ptr %58, align 8, !tbaa !22
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = load i64, ptr %8, align 8, !tbaa !12
  call void @pqueue_move_down(ptr noundef %59, i64 noundef %60)
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  %62 = icmp ne ptr %61, null
  br i1 %62, label %63, label %66

63:                                               ; preds = %15
  %64 = load i64, ptr %9, align 8, !tbaa !12
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  store i64 %64, ptr %65, align 8, !tbaa !12
  br label %66

66:                                               ; preds = %63, %15
  store i32 1, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %67

67:                                               ; preds = %66, %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %68 = load i32, ptr %4, align 4
  ret i32 %68
}

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @ossl_pqueue_reserve(ptr noundef, i64 noundef) #0

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

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

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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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, !11, i64 24}
!10 = !{!"ossl_pqueue_st", !6, i64 0, !6, i64 8, !6, i64 16, !11, i64 24, !11, i64 32, !11, i64 40}
!11 = !{!"long", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !11, i64 40}
!14 = !{!10, !6, i64 8}
!15 = !{!16, !11, i64 0}
!16 = !{!"pq_elem_st", !11, i64 0, !17, i64 8}
!17 = !{!"int", !7, i64 0}
!18 = !{!10, !6, i64 0}
!19 = !{!20, !6, i64 0}
!20 = !{!"pq_heap_st", !6, i64 0, !11, i64 8}
!21 = !{!20, !11, i64 8}
!22 = !{!16, !17, 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"

%struct.pq_elem_st = type { i64, i32 }
%struct.pq_heap_st = type { ptr, i64 }

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @ossl_pqueue_push(ptr noundef %0, ptr noundef %1, ptr noundef writeonly %2) local_unnamed_addr #0 {
  %4 = tail call i32 @ossl_pqueue_reserve(ptr noundef %0, i64 noundef 1)
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %20, label %5

5:                                                ; preds = %3
  %6 = getelementptr inbounds i8, ptr %0, i64 24
  %7 = load i64, ptr %6, align 8, !tbaa !5
  %8 = add i64 %7, 1
  store i64 %8, ptr %6, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %0, i64 40
  %10 = load i64, ptr %9, align 8, !tbaa !11
  %11 = getelementptr inbounds i8, ptr %0, i64 8
  %12 = load ptr, ptr %11, align 8, !tbaa !12
  %13 = getelementptr inbounds %struct.pq_elem_st, ptr %12, i64 %10
  %14 = load i64, ptr %13, align 8, !tbaa !13
  store i64 %14, ptr %9, align 8, !tbaa !11
  %15 = load ptr, ptr %0, align 8, !tbaa !16
  %16 = getelementptr inbounds %struct.pq_heap_st, ptr %15, i64 %7
  store ptr %1, ptr %16, align 8, !tbaa !17
  %17 = getelementptr inbounds %struct.pq_heap_st, ptr %15, i64 %7, i32 1
  store i64 %10, ptr %17, align 8, !tbaa !19
  store i64 %7, ptr %13, align 8, !tbaa !13
  %18 = getelementptr inbounds %struct.pq_elem_st, ptr %12, i64 %10, i32 1
  store i32 1, ptr %18, align 8, !tbaa !20
  tail call void @pqueue_move_down(ptr noundef nonnull %0, i64 noundef %7)
  %.not23 = icmp eq ptr %2, null
  br i1 %.not23, label %20, label %19

19:                                               ; preds = %5
  store i64 %10, ptr %2, align 8, !tbaa !21
  br label %20

20:                                               ; preds = %5, %19, %3
  %.0 = phi i32 [ 0, %3 ], [ 1, %19 ], [ 1, %5 ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @ossl_pqueue_reserve(ptr noundef, i64 noundef) local_unnamed_addr #0

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

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" }
attributes #1 = { inlinehint 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 = !{!"ossl_pqueue_st", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !10, i64 32, !10, i64 40}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !10, i64 40}
!12 = !{!6, !7, i64 8}
!13 = !{!14, !10, i64 0}
!14 = !{!"pq_elem_st", !10, i64 0, !15, i64 8}
!15 = !{!"int", !8, i64 0}
!16 = !{!6, !7, i64 0}
!17 = !{!18, !7, i64 0}
!18 = !{!"pq_heap_st", !7, i64 0, !10, i64 8}
!19 = !{!18, !10, i64 8}
!20 = !{!14, !15, i64 8}
!21 = !{!10, !10, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass