; LLVM IR from openanolis/openssl :: test (filterprov)

; 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.filter_prov_globals_st = type { ptr, ptr, [10 x %struct.anon], i32, i32, i64, i32 }
%struct.anon = type { i32, [6 x %struct.ossl_algorithm_st] }
%struct.ossl_algorithm_st = type { ptr, ptr, ptr, ptr }
%struct.ossl_dispatch_st = type { i32, ptr }

@ourglobals = external hidden global %struct.filter_prov_globals_st, align 8
@.str = external hidden unnamed_addr constant [8 x i8], align 1
@filter_dispatch_table = external hidden constant [7 x %struct.ossl_dispatch_st], align 16

; Function Attrs: nounwind uwtable
define dso_local i32 @filter_provider_init(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 8 @ourglobals, i8 0, i64 2040, i1 false)
  %10 = call ptr @OSSL_LIB_CTX_new()
  store ptr %10, ptr @ourglobals, align 8, !tbaa !9
  %11 = load ptr, ptr @ourglobals, align 8, !tbaa !9
  %12 = icmp eq ptr %11, null
  br i1 %12, label %13, label %14

13:                                               ; preds = %4
  br label %25

14:                                               ; preds = %4
  %15 = load ptr, ptr @ourglobals, align 8, !tbaa !9
  %16 = call ptr @OSSL_PROVIDER_load(ptr noundef %15, ptr noundef @.str)
  store ptr %16, ptr getelementptr inbounds (%struct.filter_prov_globals_st, ptr @ourglobals, i32 0, i32 1), align 8, !tbaa !13
  %17 = load ptr, ptr getelementptr inbounds (%struct.filter_prov_globals_st, ptr @ourglobals, i32 0, i32 1), align 8, !tbaa !13
  %18 = icmp eq ptr %17, null
  br i1 %18, label %19, label %20

19:                                               ; preds = %14
  br label %25

20:                                               ; preds = %14
  %21 = load ptr, ptr getelementptr inbounds (%struct.filter_prov_globals_st, ptr @ourglobals, i32 0, i32 1), align 8, !tbaa !13
  %22 = call ptr @OSSL_PROVIDER_get0_provider_ctx(ptr noundef %21)
  %23 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %22, ptr %23, align 8, !tbaa !5
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr @filter_dispatch_table, ptr %24, align 8, !tbaa !5
  store i32 1, ptr %5, align 4
  br label %29

25:                                               ; preds = %19, %13
  %26 = load ptr, ptr getelementptr inbounds (%struct.filter_prov_globals_st, ptr @ourglobals, i32 0, i32 1), align 8, !tbaa !13
  %27 = call i32 @OSSL_PROVIDER_unload(ptr noundef %26)
  %28 = load ptr, ptr @ourglobals, align 8, !tbaa !9
  call void @OSSL_LIB_CTX_free(ptr noundef %28)
  store i32 0, ptr %5, align 4
  br label %29

29:                                               ; preds = %25, %20
  %30 = load i32, ptr %5, align 4
  ret i32 %30
}

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

declare ptr @OSSL_LIB_CTX_new() #2

declare ptr @OSSL_PROVIDER_load(ptr noundef, ptr noundef) #2

declare ptr @OSSL_PROVIDER_get0_provider_ctx(ptr noundef) #2

declare i32 @OSSL_PROVIDER_unload(ptr noundef) #2

declare void @OSSL_LIB_CTX_free(ptr noundef) #2

attributes #0 = { 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 #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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" }

!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 = !{!"filter_prov_globals_st", !6, i64 0, !6, i64 8, !7, i64 16, !11, i64 2016, !11, i64 2020, !12, i64 2024, !11, i64 2032}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!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"

%struct.filter_prov_globals_st = type { ptr, ptr, [10 x %struct.anon], i32, i32, i64, i32 }
%struct.anon = type { i32, [6 x %struct.ossl_algorithm_st] }
%struct.ossl_algorithm_st = type { ptr, ptr, ptr, ptr }
%struct.ossl_dispatch_st = type { i32, ptr }

@ourglobals = external hidden local_unnamed_addr global %struct.filter_prov_globals_st, align 8
@.str = external hidden unnamed_addr constant [8 x i8], align 1
@filter_dispatch_table = external hidden constant [7 x %struct.ossl_dispatch_st], align 16

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @filter_provider_init(ptr nocapture noundef readnone %0, ptr nocapture noundef readnone %1, ptr nocapture noundef writeonly %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #0 {
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(2040) @ourglobals, i8 0, i64 2040, i1 false)
  %5 = tail call ptr @OSSL_LIB_CTX_new() #3
  store ptr %5, ptr @ourglobals, align 8, !tbaa !5
  %6 = icmp eq ptr %5, null
  br i1 %6, label %._crit_edge, label %7

._crit_edge:                                      ; preds = %4
  %.pre = load ptr, ptr getelementptr inbounds (i8, ptr @ourglobals, i64 8), align 8, !tbaa !12
  br label %12

7:                                                ; preds = %4
  %8 = tail call ptr @OSSL_PROVIDER_load(ptr noundef nonnull %5, ptr noundef nonnull @.str) #3
  store ptr %8, ptr getelementptr inbounds (i8, ptr @ourglobals, i64 8), align 8, !tbaa !12
  %9 = icmp eq ptr %8, null
  br i1 %9, label %12, label %10

10:                                               ; preds = %7
  %11 = tail call ptr @OSSL_PROVIDER_get0_provider_ctx(ptr noundef nonnull %8) #3
  store ptr %11, ptr %3, align 8, !tbaa !13
  store ptr @filter_dispatch_table, ptr %2, align 8, !tbaa !13
  br label %16

12:                                               ; preds = %._crit_edge, %7
  %13 = phi ptr [ %.pre, %._crit_edge ], [ null, %7 ]
  %14 = tail call i32 @OSSL_PROVIDER_unload(ptr noundef %13) #3
  %15 = load ptr, ptr @ourglobals, align 8, !tbaa !5
  tail call void @OSSL_LIB_CTX_free(ptr noundef %15) #3
  br label %16

16:                                               ; preds = %12, %10
  %.0 = phi i32 [ 0, %12 ], [ 1, %10 ]
  ret i32 %.0
}

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

declare ptr @OSSL_LIB_CTX_new() local_unnamed_addr #2

declare ptr @OSSL_PROVIDER_load(ptr noundef, ptr noundef) local_unnamed_addr #2

declare ptr @OSSL_PROVIDER_get0_provider_ctx(ptr noundef) local_unnamed_addr #2

declare i32 @OSSL_PROVIDER_unload(ptr noundef) local_unnamed_addr #2

declare void @OSSL_LIB_CTX_free(ptr noundef) local_unnamed_addr #2

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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 }

!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 = !{!"filter_prov_globals_st", !7, i64 0, !7, i64 8, !8, i64 16, !10, i64 2016, !10, i64 2020, !11, i64 2024, !10, i64 2032}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!6, !7, i64 8}
!13 = !{!7, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass