; LLVM IR from intel/intel-ipsec-mb :: test/imb-provider (prov_init)

; 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.ossl_dispatch_st = type { i32, ptr }
%struct.prov_ag_capable_st = type { %struct.ossl_algorithm_st, ptr }
%struct.ossl_algorithm_st = type { ptr, ptr, ptr, ptr }
%struct.prov_provider_ctx_st = type { ptr, ptr, ptr }

@c_get_params = external hidden global ptr, align 8
@stderr = external global ptr, align 8
@c_gettable_params = external hidden global ptr, align 8
@c_get_libctx = external hidden global ptr, align 8
@.str.7 = external hidden unnamed_addr constant [84 x i8], align 1
@prov_dispatch_table = external hidden constant [5 x %struct.ossl_dispatch_st], align 16
@prov_deflt_ciphers = external hidden constant [4 x %struct.prov_ag_capable_st], align 16
@prov_exported_ciphers = external hidden global [4 x %struct.ossl_algorithm_st], align 16
@.str.8 = external hidden unnamed_addr constant [26 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @prov_ctx_set_core_bio_method(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @prov_get_params_from_core(ptr noundef) #0

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

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

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #2

; Function Attrs: nounwind uwtable
declare dso_local void @prov_cache_exported_algorithms(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @OSSL_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
  store ptr null, ptr %11, align 8, !tbaa !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 %75

17:                                               ; preds = %4
  br label %18

18:                                               ; preds = %38, %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 %41

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 %36 [
    i32 1, label %27
    i32 2, label %30
    i32 4, label %33
  ]

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

30:                                               ; preds = %23
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = call ptr @OSSL_FUNC_core_get_params(ptr noundef %31)
  store ptr %32, ptr @c_get_params, align 8, !tbaa !5
  br label %37

33:                                               ; preds = %23
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = call ptr @OSSL_FUNC_core_get_libctx(ptr noundef %34)
  store ptr %35, ptr @c_get_libctx, align 8, !tbaa !5
  br label %37

36:                                               ; preds = %23
  br label %37

37:                                               ; preds = %36, %33, %30, %27
  br label %38

38:                                               ; preds = %37
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.ossl_dispatch_st, ptr %39, i32 1
  store ptr %40, ptr %7, align 8, !tbaa !5
  br label %18, !llvm.loop !12

41:                                               ; preds = %18
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = call i32 @prov_get_params_from_core(ptr noundef %42)
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %46, label %45

45:                                               ; preds = %41
  store i32 0, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %75

46:                                               ; preds = %41
  %47 = call i32 @bind_prov()
  %48 = icmp ne i32 %47, 0
  br i1 %48, label %50, label %49

49:                                               ; preds = %46
  br label %71

50:                                               ; preds = %46
  %51 = call ptr @CRYPTO_zalloc(i64 noundef 24, ptr noundef @.str.7, i32 noundef 272)
  store ptr %51, ptr %10, align 8, !tbaa !5
  %52 = load ptr, ptr %10, align 8, !tbaa !5
  %53 = icmp eq ptr %52, null
  br i1 %53, label %54, label %55

54:                                               ; preds = %50
  br label %71

55:                                               ; preds = %50
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = load ptr, ptr %10, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.prov_provider_ctx_st, ptr %57, i32 0, i32 0
  store ptr %56, ptr %58, align 8, !tbaa !14
  %59 = load ptr, ptr @c_get_libctx, align 8, !tbaa !5
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = call ptr %59(ptr noundef %60)
  %62 = load ptr, ptr %10, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.prov_provider_ctx_st, ptr %62, i32 0, i32 1
  store ptr %61, ptr %63, align 8, !tbaa !16
  %64 = load ptr, ptr %10, align 8, !tbaa !5
  %65 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %64, ptr %65, align 8, !tbaa !5
  %66 = call ptr @ossl_bio_prov_init_bio_method()
  store ptr %66, ptr %11, align 8, !tbaa !5
  %67 = load ptr, ptr %9, align 8, !tbaa !5
  %68 = load ptr, ptr %67, align 8, !tbaa !5
  %69 = load ptr, ptr %11, align 8, !tbaa !5
  call void @prov_ctx_set_core_bio_method(ptr noundef %68, ptr noundef %69)
  %70 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr @prov_dispatch_table, ptr %70, align 8, !tbaa !5
  call void @prov_cache_exported_algorithms(ptr noundef @prov_deflt_ciphers, ptr noundef @prov_exported_ciphers)
  store i32 1, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %75

71:                                               ; preds = %54, %49
  %72 = load ptr, ptr @stderr, align 8, !tbaa !5
  %73 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %72, ptr noundef @.str.8) #5
  %74 = load ptr, ptr %10, align 8, !tbaa !5
  call void @prov_teardown(ptr noundef %74)
  store i32 0, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %75

75:                                               ; preds = %71, %55, %45, %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  %76 = load i32, ptr %5, align 4
  ret i32 %76
}

declare i32 @ossl_prov_bio_from_dispatch(ptr noundef) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @OSSL_FUNC_core_gettable_params(ptr noundef) #4

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @OSSL_FUNC_core_get_params(ptr noundef) #4

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

declare i32 @bind_prov() #3

declare ptr @CRYPTO_zalloc(i64 noundef, ptr noundef, i32 noundef) #3

declare ptr @ossl_bio_prov_init_bio_method() #3

; Function Attrs: nounwind uwtable
declare hidden void @prov_teardown(ptr noundef) #0

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 = { 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 #3 = { "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 = { 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 #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 = !{!"prov_provider_ctx_st", !6, i64 0, !6, i64 8, !6, i64 16}
!16 = !{!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.ossl_dispatch_st = type { i32, ptr }
%struct.prov_ag_capable_st = type { %struct.ossl_algorithm_st, ptr }
%struct.ossl_algorithm_st = type { ptr, ptr, ptr, ptr }

@c_get_params = external hidden local_unnamed_addr global ptr, align 8
@stderr = external local_unnamed_addr global ptr, align 8
@c_gettable_params = external hidden local_unnamed_addr global ptr, align 8
@c_get_libctx = external hidden local_unnamed_addr global ptr, align 8
@.str.7 = external hidden unnamed_addr constant [84 x i8], align 1
@prov_dispatch_table = external hidden constant [5 x %struct.ossl_dispatch_st], align 16
@prov_deflt_ciphers = external hidden constant [4 x %struct.prov_ag_capable_st], align 16
@prov_exported_ciphers = external hidden global [4 x %struct.ossl_algorithm_st], align 16
@.str.8 = external hidden unnamed_addr constant [26 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @prov_ctx_set_core_bio_method(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @prov_get_params_from_core(ptr noundef) local_unnamed_addr #0

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @prov_cache_exported_algorithms(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @OSSL_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 %31, label %.preheader

.preheader:                                       ; preds = %4, %13
  %.020 = phi ptr [ %14, %13 ], [ %1, %4 ]
  %6 = load i32, ptr %.020, align 8, !tbaa !5
  switch i32 %6, label %13 [
    i32 0, label %15
    i32 1, label %7
    i32 2, label %9
    i32 4, label %11
  ]

7:                                                ; preds = %.preheader
  %8 = tail call ptr @OSSL_FUNC_core_gettable_params(ptr noundef nonnull %.020)
  store ptr %8, ptr @c_gettable_params, align 8, !tbaa !11
  br label %13

9:                                                ; preds = %.preheader
  %10 = tail call ptr @OSSL_FUNC_core_get_params(ptr noundef nonnull %.020)
  store ptr %10, ptr @c_get_params, align 8, !tbaa !11
  br label %13

11:                                               ; preds = %.preheader
  %12 = tail call ptr @OSSL_FUNC_core_get_libctx(ptr noundef nonnull %.020)
  store ptr %12, ptr @c_get_libctx, align 8, !tbaa !11
  br label %13

13:                                               ; preds = %.preheader, %7, %9, %11
  %14 = getelementptr inbounds i8, ptr %.020, i64 16
  br label %.preheader, !llvm.loop !12

15:                                               ; preds = %.preheader
  %16 = tail call i32 @prov_get_params_from_core(ptr noundef %0)
  %.not24 = icmp eq i32 %16, 0
  br i1 %.not24, label %31, label %17

17:                                               ; preds = %15
  %18 = tail call i32 @bind_prov() #4
  %.not25 = icmp eq i32 %18, 0
  br i1 %.not25, label %28, label %19

19:                                               ; preds = %17
  %20 = tail call ptr @CRYPTO_zalloc(i64 noundef 24, ptr noundef nonnull @.str.7, i32 noundef 272) #4
  %21 = icmp eq ptr %20, null
  br i1 %21, label %28, label %22

22:                                               ; preds = %19
  store ptr %0, ptr %20, align 8, !tbaa !14
  %23 = load ptr, ptr @c_get_libctx, align 8, !tbaa !11
  %24 = tail call ptr %23(ptr noundef %0) #4
  %25 = getelementptr inbounds i8, ptr %20, i64 8
  store ptr %24, ptr %25, align 8, !tbaa !16
  store ptr %20, ptr %3, align 8, !tbaa !11
  %26 = tail call ptr @ossl_bio_prov_init_bio_method() #4
  %27 = load ptr, ptr %3, align 8, !tbaa !11
  tail call void @prov_ctx_set_core_bio_method(ptr noundef %27, ptr noundef %26)
  store ptr @prov_dispatch_table, ptr %2, align 8, !tbaa !11
  tail call void @prov_cache_exported_algorithms(ptr noundef nonnull @prov_deflt_ciphers, ptr noundef nonnull @prov_exported_ciphers)
  br label %31

28:                                               ; preds = %19, %17
  %29 = load ptr, ptr @stderr, align 8, !tbaa !11
  %30 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %29, ptr noundef nonnull @.str.8) #5
  tail call void @prov_teardown(ptr noundef null)
  br label %31

31:                                               ; preds = %15, %4, %28, %22
  %.019 = phi i32 [ 0, %28 ], [ 1, %22 ], [ 0, %4 ], [ 0, %15 ]
  ret i32 %.019
}

declare i32 @ossl_prov_bio_from_dispatch(ptr noundef) local_unnamed_addr #2

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

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

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

declare i32 @bind_prov() local_unnamed_addr #2

declare ptr @CRYPTO_zalloc(i64 noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

declare ptr @ossl_bio_prov_init_bio_method() local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden void @prov_teardown(ptr noundef) local_unnamed_addr #0

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 = { nofree 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 #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 = { nounwind }
attributes #5 = { cold 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 = !{!10, !10, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!15, !10, i64 0}
!15 = !{!"prov_provider_ctx_st", !10, i64 0, !10, i64 8, !10, i64 16}
!16 = !{!15, !10, i64 8}


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