; LLVM IR from openanolis/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
@.str = external hidden unnamed_addr constant [66 x i8], align 1
@__func__.OSSL_provider_init = external hidden unnamed_addr constant [19 x i8], align 1
@p_test_table = external hidden constant [5 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 = %40, %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 %43

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 %38 [
    i32 1, label %23
    i32 2, label %26
    i32 5, label %29
    i32 6, label %32
    i32 7, label %35
  ]

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 %39

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 %39

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 %39

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 %39

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 %39

38:                                               ; preds = %19
  br label %39

39:                                               ; preds = %38, %35, %32, %29, %26, %23
  br label %40

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

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

47:                                               ; preds = %43
  store i32 0, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %67

48:                                               ; preds = %43
  %49 = call noalias ptr @strdup(ptr noundef @.str) #5
  %50 = load ptr, ptr %10, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.p_test_ctx, ptr %50, i32 0, i32 0
  store ptr %49, ptr %51, align 8, !tbaa !14
  %52 = call noalias ptr @strdup(ptr noundef @__func__.OSSL_provider_init) #5
  %53 = load ptr, ptr %10, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.p_test_ctx, ptr %53, i32 0, i32 1
  store ptr %52, ptr %54, align 8, !tbaa !16
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  %56 = load ptr, ptr %10, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.p_test_ctx, ptr %56, i32 0, i32 2
  store ptr %55, ptr %57, align 8, !tbaa !17
  %58 = load ptr, ptr %10, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.p_test_ctx, ptr %58, i32 0, i32 0
  %60 = load ptr, ptr %59, align 8, !tbaa !14
  %61 = load ptr, ptr %10, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.p_test_ctx, ptr %61, i32 0, i32 1
  %63 = load ptr, ptr %62, align 8, !tbaa !16
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @p_set_error(i32 noundef 57, i32 noundef 1, ptr noundef %60, i32 noundef 303, ptr noundef %63, ptr noundef null)
  %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 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr @p_test_table, ptr %66, align 8, !tbaa !5
  store i32 1, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %67

67:                                               ; preds = %48, %47
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  %68 = load i32, ptr %5, align 4
  ret i32 %68
}

; 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: 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
@.str = external hidden unnamed_addr constant [66 x i8], align 1
@__func__.OSSL_provider_init = external hidden unnamed_addr constant [19 x i8], align 1
@p_test_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_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 = %17, %4
  %.0 = phi ptr [ %1, %4 ], [ %18, %17 ]
  %6 = load i32, ptr %.0, align 8, !tbaa !5
  switch i32 %6, label %17 [
    i32 0, label %19
    i32 1, label %7
    i32 2, label %9
    i32 5, label %11
    i32 6, label %13
    i32 7, label %15
  ]

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 %17

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 %17

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 %17

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 %17

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 %17

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

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

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

27:                                               ; preds = %19, %22
  %.019 = phi i32 [ 1, %22 ], [ 0, %19 ]
  ret i32 %.019
}

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