; LLVM IR from openssl/openssl :: test (p_test)

; 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.p_test_ctx = type { ptr, ptr, ptr, ptr }

@c_gettable_params = external hidden global ptr, align 8
@c_get_params = external hidden global ptr, align 8
@c_new_error = external hidden global ptr, align 8
@c_set_error_debug = external hidden global ptr, align 8
@c_vset_error = external hidden global ptr, align 8
@c_BIO_vsnprintf = external hidden global ptr, align 8
@.str = external hidden unnamed_addr constant [63 x i8], align 1
@__func__.OSSL_provider_init = external hidden unnamed_addr constant [19 x i8], align 1
@p_test_table = external hidden constant [6 x %struct.ossl_dispatch_st], align 16

; 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
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %13 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %13, ptr %11, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %43, %4
  %15 = load ptr, ptr %11, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.ossl_dispatch_st, ptr %15, i32 0, i32 0
  %17 = load i32, ptr %16, align 8, !tbaa !9
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %19, label %46

19:                                               ; preds = %14
  %20 = load ptr, ptr %11, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.ossl_dispatch_st, ptr %20, i32 0, i32 0
  %22 = load i32, ptr %21, align 8, !tbaa !9
  switch i32 %22, label %41 [
    i32 1, label %23
    i32 2, label %26
    i32 5, label %29
    i32 6, label %32
    i32 7, label %35
    i32 47, label %38
  ]

23:                                               ; preds = %19
  %24 = load ptr, ptr %11, align 8, !tbaa !5
  %25 = call ptr @OSSL_FUNC_core_gettable_params(ptr noundef %24)
  store ptr %25, ptr @c_gettable_params, align 8, !tbaa !5
  br label %42

26:                                               ; preds = %19
  %27 = load ptr, ptr %11, align 8, !tbaa !5
  %28 = call ptr @OSSL_FUNC_core_get_params(ptr noundef %27)
  store ptr %28, ptr @c_get_params, align 8, !tbaa !5
  br label %42

29:                                               ; preds = %19
  %30 = load ptr, ptr %11, align 8, !tbaa !5
  %31 = call ptr @OSSL_FUNC_core_new_error(ptr noundef %30)
  store ptr %31, ptr @c_new_error, align 8, !tbaa !5
  br label %42

32:                                               ; preds = %19
  %33 = load ptr, ptr %11, align 8, !tbaa !5
  %34 = call ptr @OSSL_FUNC_core_set_error_debug(ptr noundef %33)
  store ptr %34, ptr @c_set_error_debug, align 8, !tbaa !5
  br label %42

35:                                               ; preds = %19
  %36 = load ptr, ptr %11, align 8, !tbaa !5
  %37 = call ptr @OSSL_FUNC_core_vset_error(ptr noundef %36)
  store ptr %37, ptr @c_vset_error, align 8, !tbaa !5
  br label %42

38:                                               ; preds = %19
  %39 = load ptr, ptr %11, align 8, !tbaa !5
  %40 = call ptr @OSSL_FUNC_BIO_vsnprintf(ptr noundef %39)
  store ptr %40, ptr @c_BIO_vsnprintf, align 8, !tbaa !5
  br label %42

41:                                               ; preds = %19
  br label %42

42:                                               ; preds = %41, %38, %35, %32, %29, %26, %23
  br label %43

43:                                               ; preds = %42
  %44 = load ptr, ptr %11, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.ossl_dispatch_st, ptr %44, i32 1
  store ptr %45, ptr %11, align 8, !tbaa !5
  br label %14, !llvm.loop !12

46:                                               ; preds = %14
  %47 = call noalias ptr @malloc(i64 noundef 32) #6
  store ptr %47, ptr %10, align 8, !tbaa !5
  %48 = load ptr, ptr %10, align 8, !tbaa !5
  %49 = icmp eq ptr %48, null
  br i1 %49, label %50, label %51

50:                                               ; preds = %46
  store i32 0, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %70

51:                                               ; preds = %46
  %52 = call noalias ptr @strdup(ptr noundef @.str) #5
  %53 = load ptr, ptr %10, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.p_test_ctx, ptr %53, i32 0, i32 0
  store ptr %52, ptr %54, align 8, !tbaa !14
  %55 = call noalias ptr @strdup(ptr noundef @__func__.OSSL_provider_init) #5
  %56 = load ptr, ptr %10, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.p_test_ctx, ptr %56, i32 0, i32 1
  store ptr %55, ptr %57, align 8, !tbaa !16
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = load ptr, ptr %10, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.p_test_ctx, ptr %59, i32 0, i32 2
  store ptr %58, ptr %60, align 8, !tbaa !17
  %61 = load ptr, ptr %10, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.p_test_ctx, ptr %61, i32 0, i32 0
  %63 = load ptr, ptr %62, align 8, !tbaa !14
  %64 = load ptr, ptr %10, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.p_test_ctx, ptr %64, i32 0, i32 1
  %66 = load ptr, ptr %65, align 8, !tbaa !16
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @p_set_error(i32 noundef 57, i32 noundef 1, ptr noundef %63, i32 noundef 329, ptr noundef %66, ptr noundef null)
  %67 = load ptr, ptr %10, align 8, !tbaa !5
  %68 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %67, ptr %68, align 8, !tbaa !5
  %69 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr @p_test_table, ptr %69, align 8, !tbaa !5
  store i32 1, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %70

70:                                               ; preds = %51, %50
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  %71 = load i32, ptr %5, align 4
  ret i32 %71
}

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

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

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

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

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

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

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #3

; Function Attrs: nounwind
declare noalias ptr @strdup(ptr noundef) #4

; Function Attrs: nounwind uwtable
declare hidden void @p_set_error(i32 noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ...) #0

; 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 = { 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 allocsize(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 "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 }
attributes #6 = { nounwind allocsize(0) }

!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 = !{!"p_test_ctx", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!16 = !{!15, !6, i64 8}
!17 = !{!15, !6, i64 16}


; 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
@c_new_error = external hidden local_unnamed_addr global ptr, align 8
@c_set_error_debug = external hidden local_unnamed_addr global ptr, align 8
@c_vset_error = external hidden local_unnamed_addr global ptr, align 8
@c_BIO_vsnprintf = external hidden local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [63 x i8], align 1
@__func__.OSSL_provider_init = external hidden unnamed_addr constant [19 x i8], align 1
@p_test_table = external hidden constant [6 x %struct.ossl_dispatch_st], align 16

; 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 writeonly %3) local_unnamed_addr #0 {
  br label %5

5:                                                ; preds = %19, %4
  %.0 = phi ptr [ %1, %4 ], [ %20, %19 ]
  %6 = load i32, ptr %.0, align 8, !tbaa !5
  switch i32 %6, label %19 [
    i32 0, label %21
    i32 1, label %7
    i32 2, label %9
    i32 5, label %11
    i32 6, label %13
    i32 7, label %15
    i32 47, label %17
  ]

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

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

11:                                               ; preds = %5
  %12 = tail call ptr @OSSL_FUNC_core_new_error(ptr noundef nonnull %.0)
  store ptr %12, ptr @c_new_error, align 8, !tbaa !11
  br label %19

13:                                               ; preds = %5
  %14 = tail call ptr @OSSL_FUNC_core_set_error_debug(ptr noundef nonnull %.0)
  store ptr %14, ptr @c_set_error_debug, align 8, !tbaa !11
  br label %19

15:                                               ; preds = %5
  %16 = tail call ptr @OSSL_FUNC_core_vset_error(ptr noundef nonnull %.0)
  store ptr %16, ptr @c_vset_error, align 8, !tbaa !11
  br label %19

17:                                               ; preds = %5
  %18 = tail call ptr @OSSL_FUNC_BIO_vsnprintf(ptr noundef nonnull %.0)
  store ptr %18, ptr @c_BIO_vsnprintf, align 8, !tbaa !11
  br label %19

19:                                               ; preds = %5, %7, %9, %11, %13, %15, %17
  %20 = getelementptr inbounds i8, ptr %.0, i64 16
  br label %5, !llvm.loop !12

21:                                               ; preds = %5
  %22 = tail call noalias dereferenceable_or_null(32) ptr @malloc(i64 noundef 32) #4
  %23 = icmp eq ptr %22, null
  br i1 %23, label %29, label %24

24:                                               ; preds = %21
  %25 = tail call noalias ptr @strdup(ptr noundef nonnull @.str) #5
  store ptr %25, ptr %22, align 8, !tbaa !14
  %26 = tail call noalias ptr @strdup(ptr noundef nonnull @__func__.OSSL_provider_init) #5
  %27 = getelementptr inbounds i8, ptr %22, i64 8
  store ptr %26, ptr %27, align 8, !tbaa !16
  %28 = getelementptr inbounds i8, ptr %22, i64 16
  store ptr %0, ptr %28, align 8, !tbaa !17
  tail call void (i32, i32, ptr, i32, ptr, ptr, ...) @p_set_error(i32 noundef 57, i32 noundef 1, ptr noundef %25, i32 noundef 329, ptr noundef %26, ptr noundef null)
  store ptr %22, ptr %3, align 8, !tbaa !11
  store ptr @p_test_table, ptr %2, align 8, !tbaa !11
  br label %29

29:                                               ; preds = %21, %24
  %.020 = phi i32 [ 1, %24 ], [ 0, %21 ]
  ret i32 %.020
}

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

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

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

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

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

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

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias ptr @strdup(ptr nocapture noundef readonly) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare hidden void @p_set_error(i32 noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef, 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 = { 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 #2 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 nofree nounwind willreturn memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 allocsize(0) }
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, !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 = !{!"p_test_ctx", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!16 = !{!15, !10, i64 8}
!17 = !{!15, !10, i64 16}


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