; LLVM IR from openssl/openssl :: ssl/quic (uint_set)

; 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.uint_set_item_st = type { %struct.anon, %struct.uint_range_st }
%struct.anon = type { ptr, ptr, ptr }
%struct.uint_range_st = type { i64, i64 }

; 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: inlinehint nounwind uwtable
declare hidden i32 @ossl_list_uint_set_is_empty(ptr noundef) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @ossl_list_uint_set_tail(ptr noundef) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @ossl_list_uint_set_prev(ptr noundef) #1

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

11:                                               ; preds = %2
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %47

12:                                               ; preds = %2
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = call ptr @ossl_list_uint_set_tail(ptr noundef %13)
  store ptr %14, ptr %6, align 8, !tbaa !5
  br label %15

15:                                               ; preds = %43, %12
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %46

18:                                               ; preds = %15
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.uint_set_item_st, ptr %19, i32 0, i32 1
  %21 = getelementptr inbounds %struct.uint_range_st, ptr %20, i32 0, i32 0
  %22 = load i64, ptr %21, align 8, !tbaa !11
  %23 = load i64, ptr %5, align 8, !tbaa !9
  %24 = icmp ule i64 %22, %23
  br i1 %24, label %25, label %33

25:                                               ; preds = %18
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.uint_set_item_st, ptr %26, i32 0, i32 1
  %28 = getelementptr inbounds %struct.uint_range_st, ptr %27, i32 0, i32 1
  %29 = load i64, ptr %28, align 8, !tbaa !15
  %30 = load i64, ptr %5, align 8, !tbaa !9
  %31 = icmp uge i64 %29, %30
  br i1 %31, label %32, label %33

32:                                               ; preds = %25
  store i32 1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %47

33:                                               ; preds = %25, %18
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.uint_set_item_st, ptr %34, i32 0, i32 1
  %36 = getelementptr inbounds %struct.uint_range_st, ptr %35, i32 0, i32 1
  %37 = load i64, ptr %36, align 8, !tbaa !15
  %38 = load i64, ptr %5, align 8, !tbaa !9
  %39 = icmp ult i64 %37, %38
  br i1 %39, label %40, label %41

40:                                               ; preds = %33
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %47

41:                                               ; preds = %33
  br label %42

42:                                               ; preds = %41
  br label %43

43:                                               ; preds = %42
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = call ptr @ossl_list_uint_set_prev(ptr noundef %44)
  store ptr %45, ptr %6, align 8, !tbaa !5
  br label %15, !llvm.loop !16

46:                                               ; preds = %15
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %47

47:                                               ; preds = %46, %40, %32, %11
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %48 = load i32, ptr %3, align 4
  ret i32 %48
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
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 = { 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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 24}
!12 = !{!"uint_set_item_st", !13, i64 0, !14, i64 24}
!13 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16}
!14 = !{!"uint_range_st", !10, i64 0, !10, i64 8}
!15 = !{!12, !10, i64 32}
!16 = distinct !{!16, !17}
!17 = !{!"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: inlinehint nounwind uwtable
declare hidden i32 @ossl_list_uint_set_is_empty(ptr noundef) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @ossl_list_uint_set_tail(ptr noundef) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @ossl_list_uint_set_prev(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @ossl_uint_set_query(ptr noundef %0, i64 noundef %1) local_unnamed_addr #1 {
  %3 = tail call i32 @ossl_list_uint_set_is_empty(ptr noundef %0)
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %4, label %.loopexit

4:                                                ; preds = %2
  %5 = tail call ptr @ossl_list_uint_set_tail(ptr noundef %0)
  %.not1215 = icmp eq ptr %5, null
  br i1 %.not1215, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %4, %9
  %.016 = phi ptr [ %10, %9 ], [ %5, %4 ]
  %6 = getelementptr inbounds i8, ptr %.016, i64 24
  %7 = load i64, ptr %6, align 8, !tbaa !5
  %.not13 = icmp ugt i64 %7, %1
  %.phi.trans.insert = getelementptr inbounds i8, ptr %.016, i64 32
  %.pre = load i64, ptr %.phi.trans.insert, align 8, !tbaa !13
  %.not14 = icmp ult i64 %.pre, %1
  %or.cond = select i1 %.not13, i1 true, i1 %.not14
  br i1 %or.cond, label %.lr.ph._crit_edge, label %.loopexit

.lr.ph._crit_edge:                                ; preds = %.lr.ph
  %8 = icmp ult i64 %.pre, %1
  br i1 %8, label %.loopexit, label %9

9:                                                ; preds = %.lr.ph._crit_edge
  %10 = tail call ptr @ossl_list_uint_set_prev(ptr noundef nonnull %.016)
  %.not12 = icmp eq ptr %10, null
  br i1 %.not12, label %.loopexit, label %.lr.ph, !llvm.loop !14

.loopexit:                                        ; preds = %.lr.ph._crit_edge, %9, %.lr.ph, %4, %2
  %.010 = phi i32 [ 0, %2 ], [ 0, %4 ], [ 0, %.lr.ph._crit_edge ], [ 0, %9 ], [ 1, %.lr.ph ]
  ret i32 %.010
}

attributes #0 = { 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 #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" }

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


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