; 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 }

@.str = external hidden unnamed_addr constant [75 x i8], align 1

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

declare void @CRYPTO_free(ptr noundef, ptr noundef, i32 noundef) #1

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

12:                                               ; preds = %67, %20, %2
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %72

15:                                               ; preds = %12
  %16 = load ptr, ptr %6, 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 !13
  %19 = icmp eq i32 %18, 1
  br i1 %19, label %20, label %25

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

25:                                               ; preds = %15
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.fd_lookup_st, ptr %26, i32 0, i32 0
  %28 = load ptr, ptr %27, align 8, !tbaa !18
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = icmp eq ptr %28, %29
  br i1 %30, label %31, label %67

31:                                               ; preds = %25
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.fd_lookup_st, ptr %32, i32 0, i32 4
  %34 = load i32, ptr %33, align 8, !tbaa !19
  %35 = icmp eq i32 %34, 1
  br i1 %35, label %36, label %60

36:                                               ; preds = %31
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.async_wait_ctx_st, ptr %37, i32 0, i32 0
  %39 = load ptr, ptr %38, align 8, !tbaa !9
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = icmp eq ptr %39, %40
  br i1 %41, label %42, label %48

42:                                               ; preds = %36
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.fd_lookup_st, ptr %43, i32 0, i32 6
  %45 = load ptr, ptr %44, align 8, !tbaa !15
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.async_wait_ctx_st, ptr %46, i32 0, i32 0
  store ptr %45, ptr %47, align 8, !tbaa !9
  br label %54

48:                                               ; preds = %36
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.fd_lookup_st, ptr %49, i32 0, i32 6
  %51 = load ptr, ptr %50, align 8, !tbaa !15
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.fd_lookup_st, ptr %52, i32 0, i32 6
  store ptr %51, ptr %53, align 8, !tbaa !15
  br label %54

54:                                               ; preds = %48, %42
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  call void @CRYPTO_free(ptr noundef %55, ptr noundef @.str, i32 noundef 164)
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.async_wait_ctx_st, ptr %56, i32 0, i32 1
  %58 = load i64, ptr %57, align 8, !tbaa !20
  %59 = add i64 %58, -1
  store i64 %59, ptr %57, align 8, !tbaa !20
  store i32 1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %73

60:                                               ; preds = %31
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.fd_lookup_st, ptr %61, i32 0, i32 5
  store i32 1, ptr %62, align 4, !tbaa !13
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.async_wait_ctx_st, ptr %63, i32 0, i32 2
  %65 = load i64, ptr %64, align 8, !tbaa !21
  %66 = add i64 %65, 1
  store i64 %66, ptr %64, align 8, !tbaa !21
  store i32 1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %73

67:                                               ; preds = %25
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %68, ptr %7, align 8, !tbaa !5
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.fd_lookup_st, ptr %69, i32 0, i32 6
  %71 = load ptr, ptr %70, align 8, !tbaa !15
  store ptr %71, ptr %6, align 8, !tbaa !5
  br label %12, !llvm.loop !16

72:                                               ; preds = %12
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %73

73:                                               ; preds = %72, %60, %54
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %74 = load i32, ptr %3, align 4
  ret i32 %74
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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, !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 = !{!14, !12, i64 36}
!14 = !{!"fd_lookup_st", !6, i64 0, !12, i64 8, !6, i64 16, !6, i64 24, !12, i64 32, !12, i64 36, !6, i64 40}
!15 = !{!14, !6, i64 40}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!14, !6, i64 0}
!19 = !{!14, !12, i64 32}
!20 = !{!10, !11, i64 8}
!21 = !{!10, !11, i64 16}


; 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"

@.str = external hidden unnamed_addr constant [75 x i8], align 1

declare void @CRYPTO_free(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @ASYNC_WAIT_CTX_clear_fd(ptr nocapture noundef %0, ptr noundef readnone %1) local_unnamed_addr #1 {
  %.02024 = load ptr, ptr %0, align 8, !tbaa !5
  %.not25 = icmp eq ptr %.02024, null
  br i1 %.not25, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %2, %.backedge
  %.02027 = phi ptr [ %.020, %.backedge ], [ %.02024, %2 ]
  %.026 = phi ptr [ %.02027, %.backedge ], [ null, %2 ]
  %3 = getelementptr inbounds i8, ptr %.02027, i64 36
  %4 = load i32, ptr %3, align 4, !tbaa !9
  %5 = icmp eq i32 %4, 1
  br i1 %5, label %.backedge, label %6

.backedge:                                        ; preds = %6, %.lr.ph
  %.020.in.be = getelementptr inbounds i8, ptr %.02027, i64 40
  %.020 = load ptr, ptr %.020.in.be, align 8, !tbaa !5
  %.not = icmp eq ptr %.020, null
  br i1 %.not, label %.loopexit, label %.lr.ph, !llvm.loop !12

6:                                                ; preds = %.lr.ph
  %7 = load ptr, ptr %.02027, align 8, !tbaa !14
  %8 = icmp eq ptr %7, %1
  br i1 %8, label %9, label %.backedge

9:                                                ; preds = %6
  %10 = getelementptr inbounds i8, ptr %.02027, i64 32
  %11 = load i32, ptr %10, align 8, !tbaa !15
  %12 = icmp eq i32 %11, 1
  br i1 %12, label %13, label %18

13:                                               ; preds = %9
  %14 = icmp eq ptr %.02024, %.02027
  %15 = getelementptr inbounds i8, ptr %.02027, i64 40
  %16 = load ptr, ptr %15, align 8, !tbaa !16
  %17 = getelementptr inbounds i8, ptr %.026, i64 40
  %.sink = select i1 %14, ptr %0, ptr %17
  store ptr %16, ptr %.sink, align 8, !tbaa !5
  tail call void @CRYPTO_free(ptr noundef nonnull %.02027, ptr noundef nonnull @.str, i32 noundef 164) #2
  br label %.loopexit.sink.split

18:                                               ; preds = %9
  %19 = getelementptr inbounds i8, ptr %.02027, i64 36
  store i32 1, ptr %19, align 4, !tbaa !9
  br label %.loopexit.sink.split

.loopexit.sink.split:                             ; preds = %13, %18
  %.sink39 = phi i64 [ 16, %18 ], [ 8, %13 ]
  %.sink37 = phi i64 [ 1, %18 ], [ -1, %13 ]
  %20 = getelementptr inbounds i8, ptr %0, i64 %.sink39
  %21 = load i64, ptr %20, align 8, !tbaa !17
  %22 = add i64 %21, %.sink37
  store i64 %22, ptr %20, align 8, !tbaa !17
  br label %.loopexit

.loopexit:                                        ; preds = %.backedge, %.loopexit.sink.split, %2
  %.021 = phi i32 [ 0, %2 ], [ 1, %.loopexit.sink.split ], [ 0, %.backedge ]
  ret i32 %.021
}

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


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