; LLVM IR from openssl/openssl :: ssl/rio (poll_builder)

; 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_TIME = type { i64 }
%struct.rio_poll_builder_st = type { ptr, [32 x %struct.pollfd], i64, i64 }
%struct.pollfd = type { i32, i16, i16 }

; 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
define dso_local i32 @ossl_rio_poll_builder_poll(ptr noundef %0, i64 %1) #1 {
  %3 = alloca %struct.OSSL_TIME, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca %struct.OSSL_TIME, align 8
  %8 = alloca %struct.OSSL_TIME, align 8
  %9 = getelementptr inbounds %struct.OSSL_TIME, ptr %3, i32 0, i32 0
  store i64 %1, ptr %9, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  br label %10

10:                                               ; preds = %57, %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  %11 = getelementptr inbounds %struct.OSSL_TIME, ptr %3, i32 0, i32 0
  %12 = load i64, ptr %11, align 8
  %13 = call i32 @ossl_time_is_infinite(i64 %12)
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %15, label %16

15:                                               ; preds = %10
  store i32 -1, ptr %6, align 4, !tbaa !9
  br label %30

16:                                               ; preds = %10
  %17 = call i64 @ossl_time_now()
  %18 = getelementptr inbounds %struct.OSSL_TIME, ptr %8, i32 0, i32 0
  store i64 %17, ptr %18, align 8
  %19 = getelementptr inbounds %struct.OSSL_TIME, ptr %3, i32 0, i32 0
  %20 = load i64, ptr %19, align 8
  %21 = getelementptr inbounds %struct.OSSL_TIME, ptr %8, i32 0, i32 0
  %22 = load i64, ptr %21, align 8
  %23 = call i64 @ossl_time_subtract(i64 %20, i64 %22)
  %24 = getelementptr inbounds %struct.OSSL_TIME, ptr %7, i32 0, i32 0
  store i64 %23, ptr %24, align 8
  %25 = getelementptr inbounds %struct.OSSL_TIME, ptr %7, i32 0, i32 0
  %26 = load i64, ptr %25, align 8
  %27 = call i64 @ossl_time2ticks(i64 %26)
  %28 = udiv i64 %27, 1000000
  %29 = trunc i64 %28 to i32
  store i32 %29, ptr %6, align 4, !tbaa !9
  br label %30

30:                                               ; preds = %16, %15
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.rio_poll_builder_st, ptr %31, i32 0, i32 0
  %33 = load ptr, ptr %32, align 8, !tbaa !11
  %34 = icmp ne ptr %33, null
  br i1 %34, label %35, label %39

35:                                               ; preds = %30
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.rio_poll_builder_st, ptr %36, i32 0, i32 0
  %38 = load ptr, ptr %37, align 8, !tbaa !11
  br label %43

39:                                               ; preds = %30
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.rio_poll_builder_st, ptr %40, i32 0, i32 1
  %42 = getelementptr inbounds [32 x %struct.pollfd], ptr %41, i64 0, i64 0
  br label %43

43:                                               ; preds = %39, %35
  %44 = phi ptr [ %38, %35 ], [ %42, %39 ]
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.rio_poll_builder_st, ptr %45, i32 0, i32 2
  %47 = load i64, ptr %46, align 8, !tbaa !14
  %48 = load i32, ptr %6, align 4, !tbaa !9
  %49 = call i32 @poll(ptr noundef %44, i64 noundef %47, i32 noundef %48)
  store i32 %49, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %50

50:                                               ; preds = %43
  %51 = load i32, ptr %5, align 4, !tbaa !9
  %52 = icmp eq i32 %51, -1
  br i1 %52, label %53, label %57

53:                                               ; preds = %50
  %54 = call ptr @__errno_location() #6
  %55 = load i32, ptr %54, align 4, !tbaa !9
  %56 = icmp eq i32 %55, 4
  br label %57

57:                                               ; preds = %53, %50
  %58 = phi i1 [ false, %50 ], [ %56, %53 ]
  br i1 %58, label %10, label %59, !llvm.loop !15

59:                                               ; preds = %57
  %60 = load i32, ptr %5, align 4, !tbaa !9
  %61 = icmp slt i32 %60, 0
  %62 = zext i1 %61 to i64
  %63 = select i1 %61, i32 0, i32 1
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  ret i32 %63
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @ossl_time_is_infinite(i64) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @ossl_time2ticks(i64) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @ossl_time_subtract(i64, i64) #2

declare i64 @ossl_time_now() #3

declare i32 @poll(ptr noundef, i64 noundef, i32 noundef) #3

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__errno_location() #4

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 = { 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 = { "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 #4 = { nounwind willreturn memory(none) "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 #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(none) }

!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 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"rio_poll_builder_st", !6, i64 0, !7, i64 8, !13, i64 264, !13, i64 272}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !13, i64 264}
!15 = distinct !{!15, !16}
!16 = !{!"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
define dso_local range(i32 0, 2) i32 @ossl_rio_poll_builder_poll(ptr noundef %0, i64 %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = getelementptr inbounds i8, ptr %0, i64 264
  br label %5

5:                                                ; preds = %19, %2
  %6 = tail call i32 @ossl_time_is_infinite(i64 %1)
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %7, label %13

7:                                                ; preds = %5
  %8 = tail call i64 @ossl_time_now() #4
  %9 = tail call i64 @ossl_time_subtract(i64 %1, i64 %8)
  %10 = tail call i64 @ossl_time2ticks(i64 %9)
  %11 = udiv i64 %10, 1000000
  %12 = trunc i64 %11 to i32
  br label %13

13:                                               ; preds = %5, %7
  %.0 = phi i32 [ %12, %7 ], [ -1, %5 ]
  %14 = load ptr, ptr %0, align 8, !tbaa !5
  %.not10 = icmp eq ptr %14, null
  %15 = select i1 %.not10, ptr %3, ptr %14
  %16 = load i64, ptr %4, align 8, !tbaa !11
  %17 = tail call i32 @poll(ptr noundef nonnull %15, i64 noundef %16, i32 noundef %.0) #4
  %18 = icmp eq i32 %17, -1
  br i1 %18, label %19, label %.critedge

19:                                               ; preds = %13
  %20 = tail call ptr @__errno_location() #5
  %21 = load i32, ptr %20, align 4, !tbaa !12
  %22 = icmp eq i32 %21, 4
  br i1 %22, label %5, label %.critedge, !llvm.loop !14

.critedge:                                        ; preds = %13, %19
  %23 = icmp sgt i32 %17, -1
  %24 = zext i1 %23 to i32
  ret i32 %24
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @ossl_time_is_infinite(i64) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @ossl_time2ticks(i64) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @ossl_time_subtract(i64, i64) local_unnamed_addr #1

declare i64 @ossl_time_now() local_unnamed_addr #2

declare i32 @poll(ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #3

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" }
attributes #2 = { "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 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 #4 = { nounwind }
attributes #5 = { nounwind willreturn memory(none) }

!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, !7, i64 0}
!6 = !{!"rio_poll_builder_st", !7, i64 0, !8, i64 8, !10, i64 264, !10, i64 272}
!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 264}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !8, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass