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

12:                                               ; preds = %56, %47, %1
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %61

15:                                               ; preds = %12
  %16 = load ptr, ptr %3, 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 !15
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %20, label %48

20:                                               ; preds = %15
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = icmp eq ptr %21, null
  br i1 %22, label %23, label %29

23:                                               ; preds = %20
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.fd_lookup_st, ptr %24, i32 0, i32 6
  %26 = load ptr, ptr %25, align 8, !tbaa !17
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.async_wait_ctx_st, ptr %27, i32 0, i32 0
  store ptr %26, ptr %28, align 8, !tbaa !14
  br label %35

29:                                               ; preds = %20
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.fd_lookup_st, ptr %30, i32 0, i32 6
  %32 = load ptr, ptr %31, align 8, !tbaa !17
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.fd_lookup_st, ptr %33, i32 0, i32 6
  store ptr %32, ptr %34, align 8, !tbaa !17
  br label %35

35:                                               ; preds = %29, %23
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  call void @CRYPTO_free(ptr noundef %36, ptr noundef @.str, i32 noundef 234)
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = icmp eq ptr %37, null
  br i1 %38, label %39, label %43

39:                                               ; preds = %35
  %40 = load ptr, ptr %2, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.async_wait_ctx_st, ptr %40, i32 0, i32 0
  %42 = load ptr, ptr %41, align 8, !tbaa !14
  store ptr %42, ptr %3, align 8, !tbaa !5
  br label %47

43:                                               ; preds = %35
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.fd_lookup_st, ptr %44, i32 0, i32 6
  %46 = load ptr, ptr %45, align 8, !tbaa !17
  store ptr %46, ptr %3, align 8, !tbaa !5
  br label %47

47:                                               ; preds = %43, %39
  br label %12, !llvm.loop !18

48:                                               ; preds = %15
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.fd_lookup_st, ptr %49, i32 0, i32 4
  %51 = load i32, ptr %50, align 8, !tbaa !20
  %52 = icmp ne i32 %51, 0
  br i1 %52, label %53, label %56

53:                                               ; preds = %48
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.fd_lookup_st, ptr %54, i32 0, i32 4
  store i32 0, ptr %55, align 8, !tbaa !20
  br label %56

56:                                               ; preds = %53, %48
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %57, ptr %4, align 8, !tbaa !5
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.fd_lookup_st, ptr %58, i32 0, i32 6
  %60 = load ptr, ptr %59, align 8, !tbaa !17
  store ptr %60, ptr %3, align 8, !tbaa !5
  br label %12, !llvm.loop !18

61:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

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


; 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 void @async_wait_ctx_reset_counts(ptr nocapture noundef %0) local_unnamed_addr #1 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %2, i8 0, i64 16, i1 false)
  %.0182225 = load ptr, ptr %0, align 8, !tbaa !5
  %.not2326 = icmp eq ptr %.0182225, null
  br i1 %.not2326, label %.outer._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1, %.outer
  %.0182228 = phi ptr [ %.01822, %.outer ], [ %.0182225, %1 ]
  %.0.ph27 = phi ptr [ %.us-phi, %.outer ], [ null, %1 ]
  %.0.ph27.fr = freeze ptr %.0.ph27
  %3 = icmp eq ptr %.0.ph27.fr, null
  %4 = getelementptr inbounds i8, ptr %.0.ph27.fr, i64 40
  %.1.in = select i1 %3, ptr %0, ptr %4
  br i1 %3, label %.lr.ph.split.us, label %.lr.ph.split

.lr.ph.split.us:                                  ; preds = %.lr.ph, %7
  %.01824.us = phi ptr [ %.018.us, %7 ], [ %.0182228, %.lr.ph ]
  %5 = getelementptr inbounds i8, ptr %.01824.us, i64 36
  %6 = load i32, ptr %5, align 4, !tbaa !9
  %.not19.us = icmp eq i32 %6, 0
  br i1 %.not19.us, label %.split.us, label %7

7:                                                ; preds = %.lr.ph.split.us
  %8 = getelementptr inbounds i8, ptr %.01824.us, i64 40
  %9 = load ptr, ptr %8, align 8, !tbaa !12
  store ptr %9, ptr %0, align 8, !tbaa !13
  tail call void @CRYPTO_free(ptr noundef nonnull %.01824.us, ptr noundef nonnull @.str, i32 noundef 234) #3
  %.018.us = load ptr, ptr %.1.in, align 8, !tbaa !5
  %.not.us = icmp eq ptr %.018.us, null
  br i1 %.not.us, label %.outer._crit_edge, label %.lr.ph.split.us, !llvm.loop !16

.lr.ph.split:                                     ; preds = %.lr.ph, %12
  %.01824 = phi ptr [ %.018, %12 ], [ %.0182228, %.lr.ph ]
  %10 = getelementptr inbounds i8, ptr %.01824, i64 36
  %11 = load i32, ptr %10, align 4, !tbaa !9
  %.not19 = icmp eq i32 %11, 0
  br i1 %.not19, label %.split.us, label %12

12:                                               ; preds = %.lr.ph.split
  %13 = getelementptr inbounds i8, ptr %.01824, i64 40
  %14 = load ptr, ptr %13, align 8, !tbaa !12
  store ptr %14, ptr %4, align 8, !tbaa !12
  tail call void @CRYPTO_free(ptr noundef nonnull %.01824, ptr noundef nonnull @.str, i32 noundef 234) #3
  %.018 = load ptr, ptr %4, align 8, !tbaa !5
  %.not = icmp eq ptr %.018, null
  br i1 %.not, label %.outer._crit_edge, label %.lr.ph.split, !llvm.loop !16

.split.us:                                        ; preds = %.lr.ph.split, %.lr.ph.split.us
  %.us-phi = phi ptr [ %.01824.us, %.lr.ph.split.us ], [ %.01824, %.lr.ph.split ]
  %15 = getelementptr inbounds i8, ptr %.us-phi, i64 32
  %16 = load i32, ptr %15, align 8, !tbaa !18
  %.not20 = icmp eq i32 %16, 0
  br i1 %.not20, label %.outer, label %17

17:                                               ; preds = %.split.us
  store i32 0, ptr %15, align 8, !tbaa !18
  br label %.outer

.outer:                                           ; preds = %17, %.split.us
  %18 = getelementptr inbounds i8, ptr %.us-phi, i64 40
  %.01822 = load ptr, ptr %18, align 8, !tbaa !5
  %.not23 = icmp eq ptr %.01822, null
  br i1 %.not23, label %.outer._crit_edge, label %.lr.ph, !llvm.loop !16

.outer._crit_edge:                                ; preds = %.outer, %12, %7, %1
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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, !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 = !{!10, !6, i64 40}
!13 = !{!14, !6, i64 0}
!14 = !{!"async_wait_ctx_st", !6, i64 0, !15, i64 8, !15, i64 16, !6, i64 24, !6, i64 32, !11, i64 40}
!15 = !{!"long", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!10, !11, i64 32}


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