; LLVM IR from intel/QAT_Engine :: qat_prov_init (OSSL_provider_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.qat_ag_capable_st = type { %struct.ossl_algorithm_st, ptr }
%struct.ossl_algorithm_st = type { ptr, ptr, ptr, ptr }
%struct.qat_provider_ctx_st = type { ptr, ptr, ptr }

@c_get_params = external hidden global ptr, align 8
@qatDebugLogFile = external 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.9 = external hidden unnamed_addr constant [66 x i8], align 1
@qat_dispatch_table = external hidden constant [6 x %struct.ossl_dispatch_st], align 16
@qat_deflt_ciphers = external hidden constant [1 x %struct.qat_ag_capable_st], align 16
@qat_exported_ciphers = external hidden global [1 x %struct.ossl_algorithm_st], align 16

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @qat_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 uwtable
declare dso_local void @qat_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) #4
  store ptr null, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  store ptr null, ptr %11, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %4
  %14 = load ptr, ptr @qatDebugLogFile, align 8, !tbaa !5
  %15 = icmp eq ptr %14, null
  br i1 %15, label %16, label %18

16:                                               ; preds = %13
  %17 = load ptr, ptr @stderr, align 8, !tbaa !5
  store ptr %17, ptr @qatDebugLogFile, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %16, %13
  br label %19

19:                                               ; preds = %18
  br label %20

20:                                               ; preds = %19
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = call i32 @ossl_prov_bio_from_dispatch(ptr noundef %21)
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %25, label %24

24:                                               ; preds = %20
  store i32 0, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %84

25:                                               ; preds = %20
  br label %26

26:                                               ; preds = %46, %25
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.ossl_dispatch_st, ptr %27, i32 0, i32 0
  %29 = load i32, ptr %28, align 8, !tbaa !9
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %31, label %49

31:                                               ; preds = %26
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.ossl_dispatch_st, ptr %32, i32 0, i32 0
  %34 = load i32, ptr %33, align 8, !tbaa !9
  switch i32 %34, label %44 [
    i32 1, label %35
    i32 2, label %38
    i32 4, label %41
  ]

35:                                               ; preds = %31
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = call ptr @OSSL_FUNC_core_gettable_params(ptr noundef %36)
  store ptr %37, ptr @c_gettable_params, align 8, !tbaa !5
  br label %45

38:                                               ; preds = %31
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = call ptr @OSSL_FUNC_core_get_params(ptr noundef %39)
  store ptr %40, ptr @c_get_params, align 8, !tbaa !5
  br label %45

41:                                               ; preds = %31
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = call ptr @OSSL_FUNC_core_get_libctx(ptr noundef %42)
  store ptr %43, ptr @c_get_libctx, align 8, !tbaa !5
  br label %45

44:                                               ; preds = %31
  br label %45

45:                                               ; preds = %44, %41, %38, %35
  br label %46

46:                                               ; preds = %45
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.ossl_dispatch_st, ptr %47, i32 1
  store ptr %48, ptr %7, align 8, !tbaa !5
  br label %26, !llvm.loop !12

49:                                               ; preds = %26
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = call i32 @qat_get_params_from_core(ptr noundef %50)
  %52 = icmp ne i32 %51, 0
  br i1 %52, label %54, label %53

53:                                               ; preds = %49
  store i32 0, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %84

54:                                               ; preds = %49
  %55 = call i32 @bind_qat(ptr noundef null, ptr noundef null)
  %56 = icmp ne i32 %55, 0
  br i1 %56, label %57, label %60

57:                                               ; preds = %54
  %58 = call i32 @qat_engine_init(ptr noundef null)
  %59 = icmp ne i32 %58, 0
  br i1 %59, label %61, label %60

60:                                               ; preds = %57, %54
  br label %82

61:                                               ; preds = %57
  %62 = call ptr @CRYPTO_zalloc(i64 noundef 24, ptr noundef @.str.9, i32 noundef 635)
  store ptr %62, ptr %10, align 8, !tbaa !5
  %63 = load ptr, ptr %10, align 8, !tbaa !5
  %64 = icmp eq ptr %63, null
  br i1 %64, label %65, label %66

65:                                               ; preds = %61
  br label %82

66:                                               ; preds = %61
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  %68 = load ptr, ptr %10, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.qat_provider_ctx_st, ptr %68, i32 0, i32 0
  store ptr %67, ptr %69, align 8, !tbaa !14
  %70 = load ptr, ptr @c_get_libctx, align 8, !tbaa !5
  %71 = load ptr, ptr %6, align 8, !tbaa !5
  %72 = call ptr %70(ptr noundef %71)
  %73 = load ptr, ptr %10, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.qat_provider_ctx_st, ptr %73, i32 0, i32 1
  store ptr %72, ptr %74, align 8, !tbaa !16
  %75 = load ptr, ptr %10, align 8, !tbaa !5
  %76 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %75, ptr %76, align 8, !tbaa !5
  %77 = call ptr @ossl_bio_prov_init_bio_method()
  store ptr %77, ptr %11, align 8, !tbaa !5
  %78 = load ptr, ptr %9, align 8, !tbaa !5
  %79 = load ptr, ptr %78, align 8, !tbaa !5
  %80 = load ptr, ptr %11, align 8, !tbaa !5
  call void @qat_prov_ctx_set_core_bio_method(ptr noundef %79, ptr noundef %80)
  %81 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr @qat_dispatch_table, ptr %81, align 8, !tbaa !5
  call void @qat_prov_cache_exported_algorithms(ptr noundef @qat_deflt_ciphers, ptr noundef @qat_exported_ciphers)
  store i32 1, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %84

82:                                               ; preds = %65, %60
  %83 = load ptr, ptr %10, align 8, !tbaa !5
  call void @qat_teardown(ptr noundef %83)
  store i32 0, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %84

84:                                               ; preds = %82, %66, %53, %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  %85 = load i32, ptr %5, align 4
  ret i32 %85
}

declare i32 @ossl_prov_bio_from_dispatch(ptr noundef) #2

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

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

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

declare i32 @bind_qat(ptr noundef, ptr noundef) #2

declare i32 @qat_engine_init(ptr noundef) #2

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

declare ptr @ossl_bio_prov_init_bio_method() #2

; Function Attrs: nounwind uwtable
declare hidden void @qat_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 = { "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 }

!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 = !{!"qat_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.qat_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
@qatDebugLogFile = external 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.9 = external hidden unnamed_addr constant [66 x i8], align 1
@qat_dispatch_table = external hidden constant [6 x %struct.ossl_dispatch_st], align 16
@qat_deflt_ciphers = external hidden constant [1 x %struct.qat_ag_capable_st], align 16
@qat_exported_ciphers = external hidden global [1 x %struct.ossl_algorithm_st], align 16

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @qat_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 = load ptr, ptr @qatDebugLogFile, align 8, !tbaa !5
  %6 = icmp eq ptr %5, null
  br i1 %6, label %7, label %9

7:                                                ; preds = %4
  %8 = load ptr, ptr @stderr, align 8, !tbaa !5
  store ptr %8, ptr @qatDebugLogFile, align 8, !tbaa !5
  br label %9

9:                                                ; preds = %7, %4
  %10 = tail call i32 @ossl_prov_bio_from_dispatch(ptr noundef %1) #3
  %.not = icmp eq i32 %10, 0
  br i1 %.not, label %36, label %.preheader

.preheader:                                       ; preds = %9, %18
  %.020 = phi ptr [ %19, %18 ], [ %1, %9 ]
  %11 = load i32, ptr %.020, align 8, !tbaa !9
  switch i32 %11, label %18 [
    i32 0, label %20
    i32 1, label %12
    i32 2, label %14
    i32 4, label %16
  ]

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

14:                                               ; preds = %.preheader
  %15 = tail call ptr @OSSL_FUNC_core_get_params(ptr noundef nonnull %.020)
  store ptr %15, ptr @c_get_params, align 8, !tbaa !5
  br label %18

16:                                               ; preds = %.preheader
  %17 = tail call ptr @OSSL_FUNC_core_get_libctx(ptr noundef nonnull %.020)
  store ptr %17, ptr @c_get_libctx, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %.preheader, %12, %14, %16
  %19 = getelementptr inbounds i8, ptr %.020, i64 16
  br label %.preheader, !llvm.loop !12

20:                                               ; preds = %.preheader
  %21 = tail call i32 @qat_get_params_from_core(ptr noundef %0)
  %.not24 = icmp eq i32 %21, 0
  br i1 %.not24, label %36, label %22

22:                                               ; preds = %20
  %23 = tail call i32 @bind_qat(ptr noundef null, ptr noundef null) #3
  %.not25 = icmp eq i32 %23, 0
  br i1 %.not25, label %35, label %24

24:                                               ; preds = %22
  %25 = tail call i32 @qat_engine_init(ptr noundef null) #3
  %.not26 = icmp eq i32 %25, 0
  br i1 %.not26, label %35, label %26

26:                                               ; preds = %24
  %27 = tail call ptr @CRYPTO_zalloc(i64 noundef 24, ptr noundef nonnull @.str.9, i32 noundef 635) #3
  %28 = icmp eq ptr %27, null
  br i1 %28, label %35, label %29

29:                                               ; preds = %26
  store ptr %0, ptr %27, align 8, !tbaa !14
  %30 = load ptr, ptr @c_get_libctx, align 8, !tbaa !5
  %31 = tail call ptr %30(ptr noundef %0) #3
  %32 = getelementptr inbounds i8, ptr %27, i64 8
  store ptr %31, ptr %32, align 8, !tbaa !16
  store ptr %27, ptr %3, align 8, !tbaa !5
  %33 = tail call ptr @ossl_bio_prov_init_bio_method() #3
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  tail call void @qat_prov_ctx_set_core_bio_method(ptr noundef %34, ptr noundef %33)
  store ptr @qat_dispatch_table, ptr %2, align 8, !tbaa !5
  tail call void @qat_prov_cache_exported_algorithms(ptr noundef nonnull @qat_deflt_ciphers, ptr noundef nonnull @qat_exported_ciphers)
  br label %36

35:                                               ; preds = %26, %22, %24
  tail call void @qat_teardown(ptr noundef null)
  br label %36

36:                                               ; preds = %20, %9, %35, %29
  %.019 = phi i32 [ 0, %35 ], [ 1, %29 ], [ 0, %9 ], [ 0, %20 ]
  ret i32 %.019
}

declare i32 @ossl_prov_bio_from_dispatch(ptr noundef) local_unnamed_addr #1

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

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

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

declare i32 @bind_qat(ptr noundef, ptr noundef) local_unnamed_addr #1

declare i32 @qat_engine_init(ptr noundef) local_unnamed_addr #1

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

declare ptr @ossl_bio_prov_init_bio_method() local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden void @qat_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 = { "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 = { 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 = !{!"qat_provider_ctx_st", !6, i64 0, !6, i64 8, !6, i64 16}
!16 = !{!15, !6, i64 8}


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