; LLVM IR from openssl/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
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  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.lifetime.start.p0(i64 8, ptr %10) #5
  store ptr null, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %13 = load ptr, ptr %7, align 8, !tbaa !5
  %14 = call i32 @ossl_prov_bio_from_dispatch(ptr noundef %13)
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %17, label %16

16:                                               ; preds = %4
  store i32 0, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %78

17:                                               ; preds = %4
  br label %18

18:                                               ; preds = %32, %17
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.ossl_dispatch_st, ptr %19, i32 0, i32 0
  %21 = load i32, ptr %20, align 8, !tbaa !9
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %23, label %35

23:                                               ; preds = %18
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.ossl_dispatch_st, ptr %24, i32 0, i32 0
  %26 = load i32, ptr %25, align 8, !tbaa !9
  switch i32 %26, label %30 [
    i32 4, label %27
  ]

27:                                               ; preds = %23
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = call ptr @OSSL_FUNC_core_get_libctx(ptr noundef %28)
  store ptr %29, ptr %10, align 8, !tbaa !5
  br label %31

30:                                               ; preds = %23
  br label %31

31:                                               ; preds = %30, %27
  br label %32

32:                                               ; preds = %31
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.ossl_dispatch_st, ptr %33, i32 1
  store ptr %34, ptr %7, align 8, !tbaa !5
  br label %18, !llvm.loop !12

35:                                               ; preds = %18
  %36 = load ptr, ptr %10, align 8, !tbaa !5
  %37 = icmp eq ptr %36, null
  br i1 %37, label %38, label %39

38:                                               ; preds = %35
  store i32 0, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %78

39:                                               ; preds = %35
  call void @llvm.memset.p0.i64(ptr align 8 @ourglobals, i8 0, i64 2040, i1 false)
  %40 = call ptr @OSSL_LIB_CTX_new()
  store ptr %40, ptr @ourglobals, align 8, !tbaa !14
  %41 = load ptr, ptr @ourglobals, align 8, !tbaa !14
  %42 = icmp eq ptr %41, null
  br i1 %42, label %43, label %44

43:                                               ; preds = %39
  br label %74

44:                                               ; preds = %39
  %45 = load ptr, ptr @ourglobals, align 8, !tbaa !14
  %46 = call ptr @OSSL_PROVIDER_load(ptr noundef %45, ptr noundef @.str)
  store ptr %46, ptr getelementptr inbounds (%struct.filter_prov_globals_st, ptr @ourglobals, i32 0, i32 1), align 8, !tbaa !17
  %47 = load ptr, ptr getelementptr inbounds (%struct.filter_prov_globals_st, ptr @ourglobals, i32 0, i32 1), align 8, !tbaa !17
  %48 = icmp eq ptr %47, null
  br i1 %48, label %49, label %50

49:                                               ; preds = %44
  br label %74

50:                                               ; preds = %44
  %51 = call ptr @ossl_prov_ctx_new()
  %52 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %51, ptr %52, align 8, !tbaa !5
  %53 = icmp eq ptr %51, null
  br i1 %53, label %57, label %54

54:                                               ; preds = %50
  %55 = call ptr @ossl_bio_prov_init_bio_method()
  store ptr %55, ptr %11, align 8, !tbaa !5
  %56 = icmp eq ptr %55, null
  br i1 %56, label %57, label %61

57:                                               ; preds = %54, %50
  %58 = load ptr, ptr %9, align 8, !tbaa !5
  %59 = load ptr, ptr %58, align 8, !tbaa !5
  call void @ossl_prov_ctx_free(ptr noundef %59)
  %60 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr null, ptr %60, align 8, !tbaa !5
  br label %74

61:                                               ; preds = %54
  %62 = load ptr, ptr %9, align 8, !tbaa !5
  %63 = load ptr, ptr %62, align 8, !tbaa !5
  %64 = load ptr, ptr %10, align 8, !tbaa !5
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = call ptr %64(ptr noundef %65)
  call void @ossl_prov_ctx_set0_libctx(ptr noundef %63, ptr noundef %66)
  %67 = load ptr, ptr %9, align 8, !tbaa !5
  %68 = load ptr, ptr %67, align 8, !tbaa !5
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  call void @ossl_prov_ctx_set0_handle(ptr noundef %68, ptr noundef %69)
  %70 = load ptr, ptr %9, align 8, !tbaa !5
  %71 = load ptr, ptr %70, align 8, !tbaa !5
  %72 = load ptr, ptr %11, align 8, !tbaa !5
  call void @ossl_prov_ctx_set0_core_bio_method(ptr noundef %71, ptr noundef %72)
  %73 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr @filter_dispatch_table, ptr %73, align 8, !tbaa !5
  store i32 1, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %78

74:                                               ; preds = %57, %49, %43
  %75 = load ptr, ptr getelementptr inbounds (%struct.filter_prov_globals_st, ptr @ourglobals, i32 0, i32 1), align 8, !tbaa !17
  %76 = call i32 @OSSL_PROVIDER_unload(ptr noundef %75)
  %77 = load ptr, ptr @ourglobals, align 8, !tbaa !14
  call void @OSSL_LIB_CTX_free(ptr noundef %77)
  store i32 0, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %78

78:                                               ; preds = %74, %61, %38, %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  %79 = load i32, ptr %5, align 4
  ret i32 %79
}

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

declare i32 @ossl_prov_bio_from_dispatch(ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @OSSL_FUNC_core_get_libctx(ptr noundef) #3

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

declare ptr @OSSL_LIB_CTX_new() #2

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

declare ptr @ossl_prov_ctx_new() #2

declare ptr @ossl_bio_prov_init_bio_method() #2

declare void @ossl_prov_ctx_free(ptr noundef) #2

declare void @ossl_prov_ctx_set0_libctx(ptr noundef, ptr noundef) #2

declare void @ossl_prov_ctx_set0_handle(ptr noundef, ptr noundef) #2

declare void @ossl_prov_ctx_set0_core_bio_method(ptr noundef, ptr noundef) #2

declare i32 @OSSL_PROVIDER_unload(ptr noundef) #2

declare void @OSSL_LIB_CTX_free(ptr noundef) #2

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

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 nosync nounwind willreturn memory(argmem: readwrite) }
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 = { inlinehint 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { 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 0}
!10 = !{!"ossl_dispatch_st", !11, i64 0, !6, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!15, !6, i64 0}
!15 = !{!"filter_prov_globals_st", !6, i64 0, !6, i64 8, !7, i64 16, !11, i64 2016, !11, i64 2020, !16, i64 2024, !11, i64 2032}
!16 = !{!"long", !7, i64 0}
!17 = !{!15, !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 noundef %0, ptr noundef %1, ptr nocapture noundef writeonly %2, ptr nocapture noundef %3) local_unnamed_addr #0 {
  %5 = tail call i32 @ossl_prov_bio_from_dispatch(ptr noundef %1) #4
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %35, label %.preheader

.preheader:                                       ; preds = %4, %9
  %.018 = phi ptr [ %10, %9 ], [ %1, %4 ]
  %.017 = phi ptr [ %.1, %9 ], [ null, %4 ]
  %6 = load i32, ptr %.018, align 8, !tbaa !5
  switch i32 %6, label %9 [
    i32 0, label %11
    i32 4, label %7
  ]

7:                                                ; preds = %.preheader
  %8 = tail call ptr @OSSL_FUNC_core_get_libctx(ptr noundef nonnull %.018)
  br label %9

9:                                                ; preds = %.preheader, %7
  %.1 = phi ptr [ %8, %7 ], [ %.017, %.preheader ]
  %10 = getelementptr inbounds i8, ptr %.018, i64 16
  br label %.preheader, !llvm.loop !11

11:                                               ; preds = %.preheader
  %12 = icmp eq ptr %.017, null
  br i1 %12, label %35, label %13

13:                                               ; preds = %11
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(2040) @ourglobals, i8 0, i64 2040, i1 false)
  %14 = tail call ptr @OSSL_LIB_CTX_new() #4
  store ptr %14, ptr @ourglobals, align 8, !tbaa !13
  %15 = icmp eq ptr %14, null
  br i1 %15, label %31, label %16

16:                                               ; preds = %13
  %17 = tail call ptr @OSSL_PROVIDER_load(ptr noundef nonnull %14, ptr noundef nonnull @.str) #4
  store ptr %17, ptr getelementptr inbounds (i8, ptr @ourglobals, i64 8), align 8, !tbaa !16
  %18 = icmp eq ptr %17, null
  br i1 %18, label %31, label %19

19:                                               ; preds = %16
  %20 = tail call ptr @ossl_prov_ctx_new() #4
  store ptr %20, ptr %3, align 8, !tbaa !17
  %21 = icmp eq ptr %20, null
  br i1 %21, label %25, label %22

22:                                               ; preds = %19
  %23 = tail call ptr @ossl_bio_prov_init_bio_method() #4
  %24 = icmp eq ptr %23, null
  %.pre = load ptr, ptr %3, align 8, !tbaa !17
  br i1 %24, label %25, label %27

25:                                               ; preds = %22, %19
  %26 = phi ptr [ %.pre, %22 ], [ null, %19 ]
  tail call void @ossl_prov_ctx_free(ptr noundef %26) #4
  store ptr null, ptr %3, align 8, !tbaa !17
  br label %31

27:                                               ; preds = %22
  %28 = tail call ptr %.017(ptr noundef %0) #4
  tail call void @ossl_prov_ctx_set0_libctx(ptr noundef %.pre, ptr noundef %28) #4
  %29 = load ptr, ptr %3, align 8, !tbaa !17
  tail call void @ossl_prov_ctx_set0_handle(ptr noundef %29, ptr noundef %0) #4
  %30 = load ptr, ptr %3, align 8, !tbaa !17
  tail call void @ossl_prov_ctx_set0_core_bio_method(ptr noundef %30, ptr noundef nonnull %23) #4
  store ptr @filter_dispatch_table, ptr %2, align 8, !tbaa !17
  br label %35

31:                                               ; preds = %16, %13, %25
  %32 = load ptr, ptr getelementptr inbounds (i8, ptr @ourglobals, i64 8), align 8, !tbaa !16
  %33 = tail call i32 @OSSL_PROVIDER_unload(ptr noundef %32) #4
  %34 = load ptr, ptr @ourglobals, align 8, !tbaa !13
  tail call void @OSSL_LIB_CTX_free(ptr noundef %34) #4
  br label %35

35:                                               ; preds = %11, %4, %31, %27
  %.0 = phi i32 [ 0, %31 ], [ 1, %27 ], [ 0, %4 ], [ 0, %11 ]
  ret i32 %.0
}

declare i32 @ossl_prov_bio_from_dispatch(ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @OSSL_FUNC_core_get_libctx(ptr noundef) local_unnamed_addr #2

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

declare ptr @OSSL_LIB_CTX_new() local_unnamed_addr #1

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

declare ptr @ossl_prov_ctx_new() local_unnamed_addr #1

declare ptr @ossl_bio_prov_init_bio_method() local_unnamed_addr #1

declare void @ossl_prov_ctx_free(ptr noundef) local_unnamed_addr #1

declare void @ossl_prov_ctx_set0_libctx(ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @ossl_prov_ctx_set0_handle(ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @ossl_prov_ctx_set0_core_bio_method(ptr noundef, ptr noundef) local_unnamed_addr #1

declare i32 @OSSL_PROVIDER_unload(ptr noundef) local_unnamed_addr #1

declare void @OSSL_LIB_CTX_free(ptr noundef) local_unnamed_addr #1

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 = { "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 = { inlinehint 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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 = !{!"ossl_dispatch_st", !7, i64 0, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !10, i64 0}
!14 = !{!"filter_prov_globals_st", !10, i64 0, !10, i64 8, !8, i64 16, !7, i64 2016, !7, i64 2020, !15, i64 2024, !7, i64 2032}
!15 = !{!"long", !8, i64 0}
!16 = !{!14, !10, i64 8}
!17 = !{!10, !10, i64 0}


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