; 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_changed_fds(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #1 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.async_wait_ctx_st, ptr %14, i32 0, i32 1
  %16 = load i64, ptr %15, align 8, !tbaa !9
  %17 = load ptr, ptr %9, align 8, !tbaa !5
  store i64 %16, ptr %17, align 8, !tbaa !13
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.async_wait_ctx_st, ptr %18, i32 0, i32 2
  %20 = load i64, ptr %19, align 8, !tbaa !14
  %21 = load ptr, ptr %11, align 8, !tbaa !5
  store i64 %20, ptr %21, align 8, !tbaa !13
  %22 = load ptr, ptr %8, align 8, !tbaa !5
  %23 = icmp eq ptr %22, null
  br i1 %23, label %24, label %28

24:                                               ; preds = %5
  %25 = load ptr, ptr %10, align 8, !tbaa !5
  %26 = icmp eq ptr %25, null
  br i1 %26, label %27, label %28

27:                                               ; preds = %24
  store i32 1, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %80

28:                                               ; preds = %24, %5
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.async_wait_ctx_st, ptr %29, i32 0, i32 0
  %31 = load ptr, ptr %30, align 8, !tbaa !15
  store ptr %31, ptr %12, align 8, !tbaa !5
  br label %32

32:                                               ; preds = %75, %28
  %33 = load ptr, ptr %12, align 8, !tbaa !5
  %34 = icmp ne ptr %33, null
  br i1 %34, label %35, label %79

35:                                               ; preds = %32
  %36 = load ptr, ptr %12, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.fd_lookup_st, ptr %36, i32 0, i32 5
  %38 = load i32, ptr %37, align 4, !tbaa !16
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %40, label %55

40:                                               ; preds = %35
  %41 = load ptr, ptr %12, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.fd_lookup_st, ptr %41, i32 0, i32 4
  %43 = load i32, ptr %42, align 8, !tbaa !18
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %55, label %45

45:                                               ; preds = %40
  %46 = load ptr, ptr %10, align 8, !tbaa !5
  %47 = icmp ne ptr %46, null
  br i1 %47, label %48, label %55

48:                                               ; preds = %45
  %49 = load ptr, ptr %12, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.fd_lookup_st, ptr %49, i32 0, i32 1
  %51 = load i32, ptr %50, align 8, !tbaa !19
  %52 = load ptr, ptr %10, align 8, !tbaa !5
  store i32 %51, ptr %52, align 4, !tbaa !20
  %53 = load ptr, ptr %10, align 8, !tbaa !5
  %54 = getelementptr inbounds i32, ptr %53, i32 1
  store ptr %54, ptr %10, align 8, !tbaa !5
  br label %55

55:                                               ; preds = %48, %45, %40, %35
  %56 = load ptr, ptr %12, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.fd_lookup_st, ptr %56, i32 0, i32 4
  %58 = load i32, ptr %57, align 8, !tbaa !18
  %59 = icmp ne i32 %58, 0
  br i1 %59, label %60, label %75

60:                                               ; preds = %55
  %61 = load ptr, ptr %12, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.fd_lookup_st, ptr %61, i32 0, i32 5
  %63 = load i32, ptr %62, align 4, !tbaa !16
  %64 = icmp ne i32 %63, 0
  br i1 %64, label %75, label %65

65:                                               ; preds = %60
  %66 = load ptr, ptr %8, align 8, !tbaa !5
  %67 = icmp ne ptr %66, null
  br i1 %67, label %68, label %75

68:                                               ; preds = %65
  %69 = load ptr, ptr %12, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.fd_lookup_st, ptr %69, i32 0, i32 1
  %71 = load i32, ptr %70, align 8, !tbaa !19
  %72 = load ptr, ptr %8, align 8, !tbaa !5
  store i32 %71, ptr %72, align 4, !tbaa !20
  %73 = load ptr, ptr %8, align 8, !tbaa !5
  %74 = getelementptr inbounds i32, ptr %73, i32 1
  store ptr %74, ptr %8, align 8, !tbaa !5
  br label %75

75:                                               ; preds = %68, %65, %60, %55
  %76 = load ptr, ptr %12, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.fd_lookup_st, ptr %76, i32 0, i32 6
  %78 = load ptr, ptr %77, align 8, !tbaa !21
  store ptr %78, ptr %12, align 8, !tbaa !5
  br label %32, !llvm.loop !22

79:                                               ; preds = %32
  store i32 1, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %80

80:                                               ; preds = %79, %27
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  %81 = load i32, ptr %6, align 4
  ret i32 %81
}

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, !11, i64 8}
!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 = !{!10, !11, i64 16}
!15 = !{!10, !6, i64 0}
!16 = !{!17, !12, i64 36}
!17 = !{!"fd_lookup_st", !6, i64 0, !12, i64 8, !6, i64 16, !6, i64 24, !12, i64 32, !12, i64 36, !6, i64 40}
!18 = !{!17, !12, i64 32}
!19 = !{!17, !12, i64 8}
!20 = !{!12, !12, i64 0}
!21 = !{!17, !6, i64 40}
!22 = distinct !{!22, !23}
!23 = !{!"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: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local noundef i32 @ASYNC_WAIT_CTX_get_changed_fds(ptr nocapture noundef readonly %0, ptr noundef writeonly %1, ptr nocapture noundef writeonly %2, ptr noundef writeonly %3, ptr nocapture noundef writeonly %4) local_unnamed_addr #0 {
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load i64, ptr %6, align 8, !tbaa !5
  store i64 %7, ptr %2, align 8, !tbaa !12
  %8 = getelementptr inbounds i8, ptr %0, i64 16
  %9 = load i64, ptr %8, align 8, !tbaa !13
  store i64 %9, ptr %4, align 8, !tbaa !12
  %10 = icmp eq ptr %1, null
  %11 = icmp eq ptr %3, null
  %or.cond = and i1 %10, %11
  br i1 %or.cond, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %5
  %.032 = load ptr, ptr %0, align 8, !tbaa !14
  %.not33 = icmp eq ptr %.032, null
  br i1 %.not33, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %34
  %.036 = phi ptr [ %.0, %34 ], [ %.032, %.preheader ]
  %.02735 = phi ptr [ %.1, %34 ], [ %3, %.preheader ]
  %.02834 = phi ptr [ %.129, %34 ], [ %1, %.preheader ]
  %12 = getelementptr inbounds i8, ptr %.036, i64 36
  %13 = load i32, ptr %12, align 4, !tbaa !15
  %.not30 = icmp eq i32 %13, 0
  br i1 %.not30, label %23, label %14

14:                                               ; preds = %.lr.ph
  %15 = getelementptr inbounds i8, ptr %.036, i64 32
  %16 = load i32, ptr %15, align 8, !tbaa !17
  %17 = icmp eq i32 %16, 0
  %18 = icmp ne ptr %.02735, null
  %or.cond3 = select i1 %17, i1 %18, i1 false
  br i1 %or.cond3, label %19, label %23

19:                                               ; preds = %14
  %20 = getelementptr inbounds i8, ptr %.036, i64 8
  %21 = load i32, ptr %20, align 8, !tbaa !18
  store i32 %21, ptr %.02735, align 4, !tbaa !19
  %22 = getelementptr inbounds i8, ptr %.02735, i64 4
  br label %23

23:                                               ; preds = %19, %14, %.lr.ph
  %.1 = phi ptr [ %22, %19 ], [ %.02735, %14 ], [ %.02735, %.lr.ph ]
  %24 = getelementptr inbounds i8, ptr %.036, i64 32
  %25 = load i32, ptr %24, align 8, !tbaa !17
  %.not31 = icmp eq i32 %25, 0
  br i1 %.not31, label %34, label %26

26:                                               ; preds = %23
  %27 = load i32, ptr %12, align 4, !tbaa !15
  %28 = icmp eq i32 %27, 0
  %29 = icmp ne ptr %.02834, null
  %or.cond5 = select i1 %28, i1 %29, i1 false
  br i1 %or.cond5, label %30, label %34

30:                                               ; preds = %26
  %31 = getelementptr inbounds i8, ptr %.036, i64 8
  %32 = load i32, ptr %31, align 8, !tbaa !18
  store i32 %32, ptr %.02834, align 4, !tbaa !19
  %33 = getelementptr inbounds i8, ptr %.02834, i64 4
  br label %34

34:                                               ; preds = %30, %26, %23
  %.129 = phi ptr [ %33, %30 ], [ %.02834, %26 ], [ %.02834, %23 ]
  %35 = getelementptr inbounds i8, ptr %.036, i64 40
  %.0 = load ptr, ptr %35, align 8, !tbaa !14
  %.not = icmp eq ptr %.0, null
  br i1 %.not, label %.loopexit, label %.lr.ph, !llvm.loop !20

.loopexit:                                        ; preds = %34, %.preheader, %5
  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, !10, i64 8}
!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 = !{!6, !10, i64 16}
!14 = !{!7, !7, i64 0}
!15 = !{!16, !11, i64 36}
!16 = !{!"fd_lookup_st", !7, i64 0, !11, i64 8, !7, i64 16, !7, i64 24, !11, i64 32, !11, i64 36, !7, i64 40}
!17 = !{!16, !11, i64 32}
!18 = !{!16, !11, i64 8}
!19 = !{!11, !11, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


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