; LLVM IR from openanolis/openssl :: providers/common (provider_seeding)

; 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_get_entropy = external hidden global ptr, align 8
@c_cleanup_entropy = external hidden global ptr, align 8
@c_get_nonce = external hidden global ptr, align 8
@c_cleanup_nonce = external hidden global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local i32 @ossl_prov_seeding_from_dispatch(ptr noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  br label %4

4:                                                ; preds = %78, %1
  %5 = load ptr, ptr %3, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.ossl_dispatch_st, ptr %5, i32 0, i32 0
  %7 = load i32, ptr %6, align 8, !tbaa !9
  %8 = icmp ne i32 %7, 0
  br i1 %8, label %9, label %81

9:                                                ; preds = %4
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.ossl_dispatch_st, ptr %10, i32 0, i32 0
  %12 = load i32, ptr %11, align 8, !tbaa !9
  switch i32 %12, label %77 [
    i32 101, label %13
    i32 102, label %29
    i32 103, label %45
    i32 104, label %61
  ]

13:                                               ; preds = %9
  br label %14

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

17:                                               ; preds = %14
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = call ptr @OSSL_FUNC_get_entropy(ptr noundef %18)
  store ptr %19, ptr @c_get_entropy, align 8, !tbaa !5
  br label %27

20:                                               ; preds = %14
  %21 = load ptr, ptr @c_get_entropy, align 8, !tbaa !5
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = call ptr @OSSL_FUNC_get_entropy(ptr noundef %22)
  %24 = icmp ne ptr %21, %23
  br i1 %24, label %25, label %26

25:                                               ; preds = %20
  store i32 0, ptr %2, align 4
  br label %82

26:                                               ; preds = %20
  br label %27

27:                                               ; preds = %26, %17
  br label %28

28:                                               ; preds = %27
  br label %77

29:                                               ; preds = %9
  br label %30

30:                                               ; preds = %29
  %31 = load ptr, ptr @c_cleanup_entropy, align 8, !tbaa !5
  %32 = icmp eq ptr %31, null
  br i1 %32, label %33, label %36

33:                                               ; preds = %30
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = call ptr @OSSL_FUNC_cleanup_entropy(ptr noundef %34)
  store ptr %35, ptr @c_cleanup_entropy, align 8, !tbaa !5
  br label %43

36:                                               ; preds = %30
  %37 = load ptr, ptr @c_cleanup_entropy, align 8, !tbaa !5
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = call ptr @OSSL_FUNC_cleanup_entropy(ptr noundef %38)
  %40 = icmp ne ptr %37, %39
  br i1 %40, label %41, label %42

41:                                               ; preds = %36
  store i32 0, ptr %2, align 4
  br label %82

42:                                               ; preds = %36
  br label %43

43:                                               ; preds = %42, %33
  br label %44

44:                                               ; preds = %43
  br label %77

45:                                               ; preds = %9
  br label %46

46:                                               ; preds = %45
  %47 = load ptr, ptr @c_get_nonce, align 8, !tbaa !5
  %48 = icmp eq ptr %47, null
  br i1 %48, label %49, label %52

49:                                               ; preds = %46
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = call ptr @OSSL_FUNC_get_nonce(ptr noundef %50)
  store ptr %51, ptr @c_get_nonce, align 8, !tbaa !5
  br label %59

52:                                               ; preds = %46
  %53 = load ptr, ptr @c_get_nonce, align 8, !tbaa !5
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = call ptr @OSSL_FUNC_get_nonce(ptr noundef %54)
  %56 = icmp ne ptr %53, %55
  br i1 %56, label %57, label %58

57:                                               ; preds = %52
  store i32 0, ptr %2, align 4
  br label %82

58:                                               ; preds = %52
  br label %59

59:                                               ; preds = %58, %49
  br label %60

60:                                               ; preds = %59
  br label %77

61:                                               ; preds = %9
  br label %62

62:                                               ; preds = %61
  %63 = load ptr, ptr @c_cleanup_nonce, align 8, !tbaa !5
  %64 = icmp eq ptr %63, null
  br i1 %64, label %65, label %68

65:                                               ; preds = %62
  %66 = load ptr, ptr %3, align 8, !tbaa !5
  %67 = call ptr @OSSL_FUNC_cleanup_nonce(ptr noundef %66)
  store ptr %67, ptr @c_cleanup_nonce, align 8, !tbaa !5
  br label %75

68:                                               ; preds = %62
  %69 = load ptr, ptr @c_cleanup_nonce, align 8, !tbaa !5
  %70 = load ptr, ptr %3, align 8, !tbaa !5
  %71 = call ptr @OSSL_FUNC_cleanup_nonce(ptr noundef %70)
  %72 = icmp ne ptr %69, %71
  br i1 %72, label %73, label %74

73:                                               ; preds = %68
  store i32 0, ptr %2, align 4
  br label %82

74:                                               ; preds = %68
  br label %75

75:                                               ; preds = %74, %65
  br label %76

76:                                               ; preds = %75
  br label %77

77:                                               ; preds = %76, %60, %44, %28, %9
  br label %78

78:                                               ; preds = %77
  %79 = load ptr, ptr %3, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.ossl_dispatch_st, ptr %79, i32 1
  store ptr %80, ptr %3, align 8, !tbaa !5
  br label %4, !llvm.loop !12

81:                                               ; preds = %4
  store i32 1, ptr %2, align 4
  br label %82

82:                                               ; preds = %81, %73, %57, %41, %25
  %83 = load i32, ptr %2, align 4
  ret i32 %83
}

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

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @OSSL_FUNC_cleanup_nonce(ptr noundef) #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 = { 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" }

!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"

@c_get_entropy = external hidden local_unnamed_addr global ptr, align 8
@c_cleanup_entropy = external hidden local_unnamed_addr global ptr, align 8
@c_get_nonce = external hidden local_unnamed_addr global ptr, align 8
@c_cleanup_nonce = external hidden local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @ossl_prov_seeding_from_dispatch(ptr noundef %0) local_unnamed_addr #0 {
  br label %2

2:                                                ; preds = %28, %1
  %.0 = phi ptr [ %0, %1 ], [ %29, %28 ]
  %3 = load i32, ptr %.0, align 8, !tbaa !5
  switch i32 %3, label %28 [
    i32 0, label %30
    i32 101, label %4
    i32 102, label %10
    i32 103, label %16
    i32 104, label %22
  ]

4:                                                ; preds = %2
  %5 = load ptr, ptr @c_get_entropy, align 8, !tbaa !11
  %6 = icmp eq ptr %5, null
  %7 = tail call ptr @OSSL_FUNC_get_entropy(ptr noundef nonnull %.0)
  br i1 %6, label %8, label %9

8:                                                ; preds = %4
  store ptr %7, ptr @c_get_entropy, align 8, !tbaa !11
  br label %28

9:                                                ; preds = %4
  %.not20 = icmp eq ptr %5, %7
  br i1 %.not20, label %28, label %30

10:                                               ; preds = %2
  %11 = load ptr, ptr @c_cleanup_entropy, align 8, !tbaa !11
  %12 = icmp eq ptr %11, null
  %13 = tail call ptr @OSSL_FUNC_cleanup_entropy(ptr noundef nonnull %.0)
  br i1 %12, label %14, label %15

14:                                               ; preds = %10
  store ptr %13, ptr @c_cleanup_entropy, align 8, !tbaa !11
  br label %28

15:                                               ; preds = %10
  %.not19 = icmp eq ptr %11, %13
  br i1 %.not19, label %28, label %30

16:                                               ; preds = %2
  %17 = load ptr, ptr @c_get_nonce, align 8, !tbaa !11
  %18 = icmp eq ptr %17, null
  %19 = tail call ptr @OSSL_FUNC_get_nonce(ptr noundef nonnull %.0)
  br i1 %18, label %20, label %21

20:                                               ; preds = %16
  store ptr %19, ptr @c_get_nonce, align 8, !tbaa !11
  br label %28

21:                                               ; preds = %16
  %.not18 = icmp eq ptr %17, %19
  br i1 %.not18, label %28, label %30

22:                                               ; preds = %2
  %23 = load ptr, ptr @c_cleanup_nonce, align 8, !tbaa !11
  %24 = icmp eq ptr %23, null
  %25 = tail call ptr @OSSL_FUNC_cleanup_nonce(ptr noundef nonnull %.0)
  br i1 %24, label %26, label %27

26:                                               ; preds = %22
  store ptr %25, ptr @c_cleanup_nonce, align 8, !tbaa !11
  br label %28

27:                                               ; preds = %22
  %.not17 = icmp eq ptr %23, %25
  br i1 %.not17, label %28, label %30

28:                                               ; preds = %2, %8, %9, %14, %15, %20, %21, %26, %27
  %29 = getelementptr inbounds i8, ptr %.0, i64 16
  br label %2, !llvm.loop !12

30:                                               ; preds = %2, %27, %21, %15, %9
  %.011 = phi i32 [ 0, %9 ], [ 0, %15 ], [ 0, %21 ], [ 0, %27 ], [ 1, %2 ]
  ret i32 %.011
}

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

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @OSSL_FUNC_cleanup_nonce(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 = { 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" }

!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,GlobalOptPass,IPSCCPPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass