; LLVM IR from openssl/openssl :: crypto/async/arch (async_posix)

; 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_fibre_st = type { %struct.ucontext_t, [1 x %struct.__jmp_buf_tag], i32 }
%struct.ucontext_t = type { i64, ptr, %struct.stack_t, %struct.mcontext_t, %struct.__sigset_t, %struct._libc_fpstate, [4 x i64] }
%struct.stack_t = type { ptr, i32, i64 }
%struct.mcontext_t = type { [23 x i64], ptr, [8 x i64] }
%struct.__sigset_t = type { [16 x i64] }
%struct._libc_fpstate = type { i16, i16, i16, i16, i64, i64, i32, i32, [8 x %struct._libc_fpxreg], [16 x %struct._libc_xmmreg], [24 x i32] }
%struct._libc_fpxreg = type { [4 x i16], i16, [3 x i16] }
%struct._libc_xmmreg = type { [4 x i32] }
%struct.__jmp_buf_tag = type { [8 x i64], i32, %struct.__sigset_t }

@async_mem_lock = external hidden global ptr, align 8
@allow_customize = external hidden global i32, align 4
@stack_alloc_impl = external hidden global ptr, align 8

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

; Function Attrs: nounwind returns_twice
declare i32 @getcontext(ptr noundef) #1

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

declare i32 @CRYPTO_THREAD_write_lock(ptr noundef) #2

declare i32 @CRYPTO_THREAD_unlock(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @async_fibre_makecontext(ptr noundef %0) #3 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.async_fibre_st, ptr %6, i32 0, i32 2
  store i32 0, ptr %7, align 8, !tbaa !9
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.async_fibre_st, ptr %8, i32 0, i32 0
  %10 = call i32 @getcontext(ptr noundef %9) #5
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %12, label %51

12:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #6
  store i64 32768, ptr %4, align 8, !tbaa !19
  %13 = load i32, ptr @allow_customize, align 4, !tbaa !20
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %15, label %23

15:                                               ; preds = %12
  %16 = load ptr, ptr @async_mem_lock, align 8, !tbaa !5
  %17 = call i32 @CRYPTO_THREAD_write_lock(ptr noundef %16)
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %20, label %19

19:                                               ; preds = %15
  store i32 0, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %48

20:                                               ; preds = %15
  store i32 0, ptr @allow_customize, align 4, !tbaa !20
  %21 = load ptr, ptr @async_mem_lock, align 8, !tbaa !5
  %22 = call i32 @CRYPTO_THREAD_unlock(ptr noundef %21)
  br label %23

23:                                               ; preds = %20, %12
  %24 = load ptr, ptr @stack_alloc_impl, align 8, !tbaa !5
  %25 = call ptr %24(ptr noundef %4)
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.async_fibre_st, ptr %26, i32 0, i32 0
  %28 = getelementptr inbounds %struct.ucontext_t, ptr %27, i32 0, i32 2
  %29 = getelementptr inbounds %struct.stack_t, ptr %28, i32 0, i32 0
  store ptr %25, ptr %29, align 8, !tbaa !21
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.async_fibre_st, ptr %30, i32 0, i32 0
  %32 = getelementptr inbounds %struct.ucontext_t, ptr %31, i32 0, i32 2
  %33 = getelementptr inbounds %struct.stack_t, ptr %32, i32 0, i32 0
  %34 = load ptr, ptr %33, align 8, !tbaa !21
  %35 = icmp ne ptr %34, null
  br i1 %35, label %36, label %47

36:                                               ; preds = %23
  %37 = load i64, ptr %4, align 8, !tbaa !19
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.async_fibre_st, ptr %38, i32 0, i32 0
  %40 = getelementptr inbounds %struct.ucontext_t, ptr %39, i32 0, i32 2
  %41 = getelementptr inbounds %struct.stack_t, ptr %40, i32 0, i32 2
  store i64 %37, ptr %41, align 8, !tbaa !22
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.async_fibre_st, ptr %42, i32 0, i32 0
  %44 = getelementptr inbounds %struct.ucontext_t, ptr %43, i32 0, i32 1
  store ptr null, ptr %44, align 8, !tbaa !23
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.async_fibre_st, ptr %45, i32 0, i32 0
  call void (ptr, ptr, i32, ...) @makecontext(ptr noundef %46, ptr noundef @async_start_func, i32 noundef 0) #6
  store i32 1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %48

47:                                               ; preds = %23
  store i32 0, ptr %5, align 4
  br label %48

48:                                               ; preds = %47, %36, %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #6
  %49 = load i32, ptr %5, align 4
  switch i32 %49, label %59 [
    i32 0, label %50
    i32 1, label %57
  ]

50:                                               ; preds = %48
  br label %56

51:                                               ; preds = %1
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.async_fibre_st, ptr %52, i32 0, i32 0
  %54 = getelementptr inbounds %struct.ucontext_t, ptr %53, i32 0, i32 2
  %55 = getelementptr inbounds %struct.stack_t, ptr %54, i32 0, i32 0
  store ptr null, ptr %55, align 8, !tbaa !21
  br label %56

56:                                               ; preds = %51, %50
  store i32 0, ptr %2, align 4
  br label %57

57:                                               ; preds = %56, %48
  %58 = load i32, ptr %2, align 4
  ret i32 %58

59:                                               ; preds = %48
  unreachable
}

; Function Attrs: nounwind
declare void @makecontext(ptr noundef, ptr noundef, i32 noundef, ...) #4

declare void @async_start_func() #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind returns_twice "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 = { 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 #4 = { nounwind "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 returns_twice }
attributes #6 = { 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, !14, i64 1168}
!10 = !{!"async_fibre_st", !11, i64 0, !7, i64 968, !14, i64 1168}
!11 = !{!"ucontext_t", !12, i64 0, !6, i64 8, !13, i64 16, !15, i64 40, !16, i64 296, !17, i64 424, !7, i64 936}
!12 = !{!"long", !7, i64 0}
!13 = !{!"", !6, i64 0, !14, i64 8, !12, i64 16}
!14 = !{!"int", !7, i64 0}
!15 = !{!"", !7, i64 0, !6, i64 184, !7, i64 192}
!16 = !{!"", !7, i64 0}
!17 = !{!"_libc_fpstate", !18, i64 0, !18, i64 2, !18, i64 4, !18, i64 6, !12, i64 8, !12, i64 16, !14, i64 24, !14, i64 28, !7, i64 32, !7, i64 160, !7, i64 416}
!18 = !{!"short", !7, i64 0}
!19 = !{!12, !12, i64 0}
!20 = !{!14, !14, i64 0}
!21 = !{!10, !6, i64 16}
!22 = !{!10, !12, i64 32}
!23 = !{!10, !6, i64 8}


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

@async_mem_lock = external hidden local_unnamed_addr global ptr, align 8
@allow_customize = external hidden local_unnamed_addr global i32, align 4
@stack_alloc_impl = external hidden local_unnamed_addr global ptr, align 8

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

; Function Attrs: nounwind returns_twice
declare i32 @getcontext(ptr noundef) local_unnamed_addr #1

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

declare i32 @CRYPTO_THREAD_write_lock(ptr noundef) local_unnamed_addr #2

declare i32 @CRYPTO_THREAD_unlock(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @async_fibre_makecontext(ptr noundef %0) local_unnamed_addr #3 {
  %2 = alloca i64, align 8
  %3 = getelementptr inbounds i8, ptr %0, i64 1168
  store i32 0, ptr %3, align 8, !tbaa !5
  %4 = call i32 @getcontext(ptr noundef %0) #5
  %5 = icmp eq i32 %4, 0
  br i1 %5, label %6, label %23

6:                                                ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #6
  store i64 32768, ptr %2, align 8, !tbaa !18
  %7 = load i32, ptr @allow_customize, align 4, !tbaa !19
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %14, label %8

8:                                                ; preds = %6
  %9 = load ptr, ptr @async_mem_lock, align 8, !tbaa !20
  %10 = call i32 @CRYPTO_THREAD_write_lock(ptr noundef %9) #6
  %.not10 = icmp eq i32 %10, 0
  br i1 %.not10, label %.thread, label %11

11:                                               ; preds = %8
  store i32 0, ptr @allow_customize, align 4, !tbaa !19
  %12 = load ptr, ptr @async_mem_lock, align 8, !tbaa !20
  %13 = call i32 @CRYPTO_THREAD_unlock(ptr noundef %12) #6
  br label %14

14:                                               ; preds = %11, %6
  %15 = load ptr, ptr @stack_alloc_impl, align 8, !tbaa !20
  %16 = call ptr %15(ptr noundef nonnull %2) #6
  %17 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %16, ptr %17, align 8, !tbaa !21
  %.not11 = icmp eq ptr %16, null
  br i1 %.not11, label %22, label %18

18:                                               ; preds = %14
  %19 = load i64, ptr %2, align 8, !tbaa !18
  %20 = getelementptr inbounds i8, ptr %0, i64 32
  store i64 %19, ptr %20, align 8, !tbaa !22
  %21 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr null, ptr %21, align 8, !tbaa !23
  call void (ptr, ptr, i32, ...) @makecontext(ptr noundef nonnull %0, ptr noundef nonnull @async_start_func, i32 noundef 0) #6
  br label %.thread

.thread:                                          ; preds = %18, %8
  %.09.ph = phi i32 [ 0, %8 ], [ 1, %18 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #6
  br label %25

22:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #6
  br label %25

23:                                               ; preds = %1
  %24 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr null, ptr %24, align 8, !tbaa !21
  br label %25

25:                                               ; preds = %23, %22, %.thread
  %.1 = phi i32 [ %.09.ph, %.thread ], [ 0, %22 ], [ 0, %23 ]
  ret i32 %.1
}

; Function Attrs: nounwind
declare void @makecontext(ptr noundef, ptr noundef, i32 noundef, ...) local_unnamed_addr #4

declare void @async_start_func() #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind returns_twice "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 = { 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 #4 = { nounwind "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 returns_twice }
attributes #6 = { 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, !13, i64 1168}
!6 = !{!"async_fibre_st", !7, i64 0, !9, i64 968, !13, i64 1168}
!7 = !{!"ucontext_t", !8, i64 0, !11, i64 8, !12, i64 16, !14, i64 40, !15, i64 296, !16, i64 424, !9, i64 936}
!8 = !{!"long", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"any pointer", !9, i64 0}
!12 = !{!"", !11, i64 0, !13, i64 8, !8, i64 16}
!13 = !{!"int", !9, i64 0}
!14 = !{!"", !9, i64 0, !11, i64 184, !9, i64 192}
!15 = !{!"", !9, i64 0}
!16 = !{!"_libc_fpstate", !17, i64 0, !17, i64 2, !17, i64 4, !17, i64 6, !8, i64 8, !8, i64 16, !13, i64 24, !13, i64 28, !9, i64 32, !9, i64 160, !9, i64 416}
!17 = !{!"short", !9, i64 0}
!18 = !{!8, !8, i64 0}
!19 = !{!13, !13, i64 0}
!20 = !{!11, !11, i64 0}
!21 = !{!6, !11, i64 16}
!22 = !{!6, !8, i64 32}
!23 = !{!6, !11, i64 8}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass