; LLVM IR from openssl/openssl :: providers (baseprov)

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

@c_gettable_params = external hidden global ptr, align 8
@c_get_params = external hidden global ptr, align 8
@base_dispatch_table = external hidden constant [5 x %struct.ossl_dispatch_st], align 16

; Function Attrs: nounwind uwtable
define dso_local i32 @ossl_base_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
  %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 %72

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 %10, 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 %10, align 8, !tbaa !5
  %43 = icmp eq ptr %42, null
  br i1 %43, label %44, label %45

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

45:                                               ; preds = %41
  %46 = call ptr @ossl_prov_ctx_new()
  %47 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %46, ptr %47, align 8, !tbaa !5
  %48 = icmp eq ptr %46, null
  br i1 %48, label %52, label %49

49:                                               ; preds = %45
  %50 = call ptr @ossl_bio_prov_init_bio_method()
  store ptr %50, ptr %11, align 8, !tbaa !5
  %51 = icmp eq ptr %50, null
  br i1 %51, label %52, label %56

52:                                               ; preds = %49, %45
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  %54 = load ptr, ptr %53, align 8, !tbaa !5
  call void @ossl_prov_ctx_free(ptr noundef %54)
  %55 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr null, ptr %55, align 8, !tbaa !5
  store i32 0, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %72

56:                                               ; preds = %49
  %57 = load ptr, ptr %9, align 8, !tbaa !5
  %58 = load ptr, ptr %57, align 8, !tbaa !5
  %59 = load ptr, ptr %10, align 8, !tbaa !5
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = call ptr %59(ptr noundef %60)
  call void @ossl_prov_ctx_set0_libctx(ptr noundef %58, ptr noundef %61)
  %62 = load ptr, ptr %9, align 8, !tbaa !5
  %63 = load ptr, ptr %62, align 8, !tbaa !5
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  call void @ossl_prov_ctx_set0_handle(ptr noundef %63, ptr noundef %64)
  %65 = load ptr, ptr %9, align 8, !tbaa !5
  %66 = load ptr, ptr %65, align 8, !tbaa !5
  %67 = load ptr, ptr %11, align 8, !tbaa !5
  call void @ossl_prov_ctx_set0_core_bio_method(ptr noundef %66, ptr noundef %67)
  %68 = load ptr, ptr %9, align 8, !tbaa !5
  %69 = load ptr, ptr %68, align 8, !tbaa !5
  %70 = load ptr, ptr @c_get_params, align 8, !tbaa !5
  call void @ossl_prov_ctx_set0_core_get_params(ptr noundef %69, ptr noundef %70)
  %71 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr @base_dispatch_table, ptr %71, align 8, !tbaa !5
  store i32 1, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %72

72:                                               ; preds = %56, %52, %44, %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  %73 = load i32, ptr %5, align 4
  ret i32 %73
}

; 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_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 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 void @ossl_prov_ctx_set0_core_get_params(ptr noundef, 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 = { 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"}


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

@c_gettable_params = external hidden local_unnamed_addr global ptr, align 8
@c_get_params = external hidden local_unnamed_addr global ptr, align 8
@base_dispatch_table = external hidden constant [5 x %struct.ossl_dispatch_st], align 16

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @ossl_base_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) #3
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %31, label %.preheader

.preheader:                                       ; preds = %4, %13
  %.021 = phi ptr [ %14, %13 ], [ %1, %4 ]
  %.020 = phi ptr [ %.1, %13 ], [ null, %4 ]
  %6 = load i32, ptr %.021, 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 %.021)
  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 %.021)
  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 %.021)
  br label %13

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

15:                                               ; preds = %.preheader
  %16 = icmp eq ptr %.020, null
  br i1 %16, label %31, label %17

17:                                               ; preds = %15
  %18 = tail call ptr @ossl_prov_ctx_new() #3
  store ptr %18, ptr %3, align 8, !tbaa !11
  %19 = icmp eq ptr %18, null
  br i1 %19, label %23, label %20

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

23:                                               ; preds = %20, %17
  %24 = phi ptr [ %.pre, %20 ], [ null, %17 ]
  tail call void @ossl_prov_ctx_free(ptr noundef %24) #3
  store ptr null, ptr %3, align 8, !tbaa !11
  br label %31

25:                                               ; preds = %20
  %26 = tail call ptr %.020(ptr noundef %0) #3
  tail call void @ossl_prov_ctx_set0_libctx(ptr noundef %.pre, ptr noundef %26) #3
  %27 = load ptr, ptr %3, align 8, !tbaa !11
  tail call void @ossl_prov_ctx_set0_handle(ptr noundef %27, ptr noundef %0) #3
  %28 = load ptr, ptr %3, align 8, !tbaa !11
  tail call void @ossl_prov_ctx_set0_core_bio_method(ptr noundef %28, ptr noundef nonnull %21) #3
  %29 = load ptr, ptr %3, align 8, !tbaa !11
  %30 = load ptr, ptr @c_get_params, align 8, !tbaa !11
  tail call void @ossl_prov_ctx_set0_core_get_params(ptr noundef %29, ptr noundef %30) #3
  store ptr @base_dispatch_table, ptr %2, align 8, !tbaa !11
  br label %31

31:                                               ; preds = %15, %4, %25, %23
  %.0 = phi i32 [ 0, %23 ], [ 1, %25 ], [ 0, %4 ], [ 0, %15 ]
  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_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 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 void @ossl_prov_ctx_set0_core_get_params(ptr noundef, 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 = { 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"}


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