; LLVM IR from openssl/openssl :: crypto/async (async_wait)

; 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.async_wait_ctx_st = type { ptr, i64, i64, ptr, ptr, i32 }
%struct.fd_lookup_st = type { ptr, i32, ptr, ptr, i32, i32, 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
define dso_local i32 @ASYNC_WAIT_CTX_get_all_fds(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.async_wait_ctx_st, ptr %8, i32 0, i32 0
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  store ptr %10, ptr %7, align 8, !tbaa !5
  %11 = load ptr, ptr %6, align 8, !tbaa !5
  store i64 0, ptr %11, align 8, !tbaa !13
  br label %12

12:                                               ; preds = %34, %20, %3
  %13 = load ptr, ptr %7, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %41

15:                                               ; preds = %12
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.fd_lookup_st, ptr %16, i32 0, i32 5
  %18 = load i32, ptr %17, align 4, !tbaa !14
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %20, label %24

20:                                               ; preds = %15
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.fd_lookup_st, ptr %21, i32 0, i32 6
  %23 = load ptr, ptr %22, align 8, !tbaa !16
  store ptr %23, ptr %7, align 8, !tbaa !5
  br label %12, !llvm.loop !17

24:                                               ; preds = %15
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = icmp ne ptr %25, null
  br i1 %26, label %27, label %34

27:                                               ; preds = %24
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.fd_lookup_st, ptr %28, i32 0, i32 1
  %30 = load i32, ptr %29, align 8, !tbaa !19
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 %30, ptr %31, align 4, !tbaa !20
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds i32, ptr %32, i32 1
  store ptr %33, ptr %5, align 8, !tbaa !5
  br label %34

34:                                               ; preds = %27, %24
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = load i64, ptr %35, align 8, !tbaa !13
  %37 = add i64 %36, 1
  store i64 %37, ptr %35, align 8, !tbaa !13
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.fd_lookup_st, ptr %38, i32 0, i32 6
  %40 = load ptr, ptr %39, align 8, !tbaa !16
  store ptr %40, ptr %7, align 8, !tbaa !5
  br label %12, !llvm.loop !17

41:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret i32 1
}

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 0}
!10 = !{!"async_wait_ctx_st", !6, i64 0, !11, i64 8, !11, i64 16, !6, i64 24, !6, i64 32, !12, i64 40}
!11 = !{!"long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!11, !11, i64 0}
!14 = !{!15, !12, i64 36}
!15 = !{!"fd_lookup_st", !6, i64 0, !12, i64 8, !6, i64 16, !6, i64 24, !12, i64 32, !12, i64 36, !6, i64 40}
!16 = !{!15, !6, i64 40}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!15, !12, i64 8}
!20 = !{!12, !12, i64 0}


; 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: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local noundef i32 @ASYNC_WAIT_CTX_get_all_fds(ptr nocapture noundef readonly %0, ptr noundef writeonly %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #0 {
  %4 = load ptr, ptr %0, align 8, !tbaa !5
  store i64 0, ptr %2, align 8, !tbaa !12
  %.not1517 = icmp eq ptr %4, null
  br i1 %.not1517, label %.outer._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3, %.outer
  %5 = phi i64 [ %17, %.outer ], [ 0, %3 ]
  %.0.ph19 = phi ptr [ %19, %.outer ], [ %4, %3 ]
  %.011.ph18 = phi ptr [ %.1, %.outer ], [ %1, %3 ]
  br label %6

6:                                                ; preds = %.lr.ph, %9
  %.016 = phi ptr [ %.0.ph19, %.lr.ph ], [ %11, %9 ]
  %7 = getelementptr inbounds i8, ptr %.016, i64 36
  %8 = load i32, ptr %7, align 4, !tbaa !13
  %.not12 = icmp eq i32 %8, 0
  br i1 %.not12, label %12, label %9

9:                                                ; preds = %6
  %10 = getelementptr inbounds i8, ptr %.016, i64 40
  %11 = load ptr, ptr %10, align 8, !tbaa !15
  %.not = icmp eq ptr %11, null
  br i1 %.not, label %.outer._crit_edge, label %6, !llvm.loop !16

12:                                               ; preds = %6
  %.not13 = icmp eq ptr %.011.ph18, null
  br i1 %.not13, label %.outer, label %13

13:                                               ; preds = %12
  %14 = getelementptr inbounds i8, ptr %.016, i64 8
  %15 = load i32, ptr %14, align 8, !tbaa !18
  store i32 %15, ptr %.011.ph18, align 4, !tbaa !19
  %16 = getelementptr inbounds i8, ptr %.011.ph18, i64 4
  br label %.outer

.outer:                                           ; preds = %13, %12
  %.1 = phi ptr [ %16, %13 ], [ null, %12 ]
  %17 = add i64 %5, 1
  store i64 %17, ptr %2, align 8, !tbaa !12
  %18 = getelementptr inbounds i8, ptr %.016, i64 40
  %19 = load ptr, ptr %18, align 8, !tbaa !15
  %.not15 = icmp eq ptr %19, null
  br i1 %.not15, label %.outer._crit_edge, label %.lr.ph, !llvm.loop !16

.outer._crit_edge:                                ; preds = %.outer, %9, %3
  ret i32 1
}

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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, !7, i64 0}
!6 = !{!"async_wait_ctx_st", !7, i64 0, !10, i64 8, !10, i64 16, !7, i64 24, !7, i64 32, !11, 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 = !{!"int", !8, i64 0}
!12 = !{!10, !10, i64 0}
!13 = !{!14, !11, i64 36}
!14 = !{!"fd_lookup_st", !7, i64 0, !11, i64 8, !7, i64 16, !7, i64 24, !11, i64 32, !11, i64 36, !7, i64 40}
!15 = !{!14, !7, i64 40}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!14, !11, i64 8}
!19 = !{!11, !11, i64 0}


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