; LLVM IR from openssl/openssl :: crypto/rsa (rsa_sp800_56b_gen)

; 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.rsa_st = type { i32, ptr, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, %struct.rsa_pss_params_30_st, ptr, ptr, %struct.crypto_ex_data_st, %struct.CRYPTO_REF_COUNT, i32, ptr, ptr, ptr, ptr, ptr, ptr, i32 }
%struct.rsa_pss_params_30_st = type { i32, %struct.anon, i32, i32 }
%struct.anon = type { i32, i32 }
%struct.crypto_ex_data_st = type { ptr, ptr }
%struct.CRYPTO_REF_COUNT = type { i32 }

; Function Attrs: nounwind uwtable
declare dso_local i32 @ossl_rsa_fips186_4_gen_prob_primes(ptr noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, 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 i32 @ossl_rsa_sp800_56b_validate_strength(i32 noundef, i32 noundef) #0

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

declare void @BN_free(ptr noundef) #2

declare ptr @BN_new() #2

; Function Attrs: nounwind uwtable
define dso_local i32 @ossl_rsa_sp800_56b_generate_key(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  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 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  store ptr null, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  store ptr null, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  store ptr null, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  %17 = load i32, ptr %7, align 4, !tbaa !9
  %18 = call i32 @ossl_rsa_sp800_56b_validate_strength(i32 noundef %17, i32 noundef -1)
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %21, label %20

20:                                               ; preds = %4
  store i32 0, ptr %5, align 4
  store i32 1, ptr %16, align 4
  br label %114

21:                                               ; preds = %4
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.rsa_st, ptr %22, i32 0, i32 1
  %24 = load ptr, ptr %23, align 8, !tbaa !11
  %25 = call ptr @RAND_get0_private(ptr noundef %24)
  %26 = load i32, ptr %7, align 4, !tbaa !9
  %27 = call i32 @rsa_validate_rng_strength(ptr noundef %25, i32 noundef %26)
  %28 = icmp ne i32 %27, 0
  br i1 %28, label %30, label %29

29:                                               ; preds = %21
  store i32 0, ptr %5, align 4
  store i32 1, ptr %16, align 4
  br label %114

30:                                               ; preds = %21
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.rsa_st, ptr %31, i32 0, i32 1
  %33 = load ptr, ptr %32, align 8, !tbaa !11
  %34 = call ptr @BN_CTX_new_ex(ptr noundef %33)
  store ptr %34, ptr %12, align 8, !tbaa !5
  %35 = load ptr, ptr %12, align 8, !tbaa !5
  %36 = icmp eq ptr %35, null
  br i1 %36, label %37, label %38

37:                                               ; preds = %30
  store i32 0, ptr %5, align 4
  store i32 1, ptr %16, align 4
  br label %114

38:                                               ; preds = %30
  %39 = load ptr, ptr %8, align 8, !tbaa !5
  %40 = icmp eq ptr %39, null
  br i1 %40, label %41, label %51

41:                                               ; preds = %38
  %42 = call ptr @BN_new()
  store ptr %42, ptr %13, align 8, !tbaa !5
  %43 = load ptr, ptr %13, align 8, !tbaa !5
  %44 = icmp eq ptr %43, null
  br i1 %44, label %49, label %45

45:                                               ; preds = %41
  %46 = load ptr, ptr %13, align 8, !tbaa !5
  %47 = call i32 @BN_set_word(ptr noundef %46, i64 noundef 65537)
  %48 = icmp ne i32 %47, 0
  br i1 %48, label %50, label %49

49:                                               ; preds = %45, %41
  br label %106

50:                                               ; preds = %45
  br label %53

51:                                               ; preds = %38
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %52, ptr %13, align 8, !tbaa !5
  br label %53

53:                                               ; preds = %51, %50
  br label %54

54:                                               ; preds = %101, %53
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  %56 = load ptr, ptr %14, align 8, !tbaa !5
  %57 = load i32, ptr %7, align 4, !tbaa !9
  %58 = load ptr, ptr %13, align 8, !tbaa !5
  %59 = load ptr, ptr %12, align 8, !tbaa !5
  %60 = load ptr, ptr %9, align 8, !tbaa !5
  %61 = call i32 @ossl_rsa_fips186_4_gen_prob_primes(ptr noundef %55, ptr noundef %56, i32 noundef %57, ptr noundef %58, ptr noundef %59, ptr noundef %60)
  %62 = icmp ne i32 %61, 0
  br i1 %62, label %64, label %63

63:                                               ; preds = %54
  br label %106

64:                                               ; preds = %54
  %65 = load ptr, ptr %14, align 8, !tbaa !5
  %66 = icmp eq ptr %65, null
  br i1 %66, label %67, label %88

67:                                               ; preds = %64
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.rsa_st, ptr %68, i32 0, i32 8
  %70 = load ptr, ptr %69, align 8, !tbaa !17
  %71 = load ptr, ptr %6, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.rsa_st, ptr %71, i32 0, i32 9
  %73 = load ptr, ptr %72, align 8, !tbaa !18
  %74 = call i32 @BN_cmp(ptr noundef %70, ptr noundef %73)
  %75 = icmp slt i32 %74, 0
  br i1 %75, label %76, label %88

76:                                               ; preds = %67
  %77 = load ptr, ptr %6, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.rsa_st, ptr %77, i32 0, i32 8
  %79 = load ptr, ptr %78, align 8, !tbaa !17
  store ptr %79, ptr %15, align 8, !tbaa !5
  %80 = load ptr, ptr %6, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.rsa_st, ptr %80, i32 0, i32 9
  %82 = load ptr, ptr %81, align 8, !tbaa !18
  %83 = load ptr, ptr %6, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.rsa_st, ptr %83, i32 0, i32 8
  store ptr %82, ptr %84, align 8, !tbaa !17
  %85 = load ptr, ptr %15, align 8, !tbaa !5
  %86 = load ptr, ptr %6, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.rsa_st, ptr %86, i32 0, i32 9
  store ptr %85, ptr %87, align 8, !tbaa !18
  br label %88

88:                                               ; preds = %76, %67, %64
  %89 = load ptr, ptr %6, align 8, !tbaa !5
  %90 = load i32, ptr %7, align 4, !tbaa !9
  %91 = load ptr, ptr %13, align 8, !tbaa !5
  %92 = load ptr, ptr %12, align 8, !tbaa !5
  %93 = call i32 @ossl_rsa_sp800_56b_derive_params_from_pq(ptr noundef %89, i32 noundef %90, ptr noundef %91, ptr noundef %92)
  store i32 %93, ptr %11, align 4, !tbaa !9
  %94 = load i32, ptr %11, align 4, !tbaa !9
  %95 = icmp slt i32 %94, 0
  br i1 %95, label %96, label %97

96:                                               ; preds = %88
  br label %106

97:                                               ; preds = %88
  %98 = load i32, ptr %11, align 4, !tbaa !9
  %99 = icmp sgt i32 %98, 0
  br i1 %99, label %100, label %101

100:                                              ; preds = %97
  br label %102

101:                                              ; preds = %97
  br label %54

102:                                              ; preds = %100
  %103 = load ptr, ptr %6, align 8, !tbaa !5
  %104 = load ptr, ptr %12, align 8, !tbaa !5
  %105 = call i32 @ossl_rsa_sp800_56b_pairwise_test(ptr noundef %103, ptr noundef %104)
  store i32 %105, ptr %10, align 4, !tbaa !9
  br label %106

106:                                              ; preds = %102, %96, %63, %49
  %107 = load ptr, ptr %8, align 8, !tbaa !5
  %108 = icmp eq ptr %107, null
  br i1 %108, label %109, label %111

109:                                              ; preds = %106
  %110 = load ptr, ptr %13, align 8, !tbaa !5
  call void @BN_free(ptr noundef %110)
  br label %111

111:                                              ; preds = %109, %106
  %112 = load ptr, ptr %12, align 8, !tbaa !5
  call void @BN_CTX_free(ptr noundef %112)
  %113 = load i32, ptr %10, align 4, !tbaa !9
  store i32 %113, ptr %5, align 4
  store i32 1, ptr %16, align 4
  br label %114

114:                                              ; preds = %111, %37, %29, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %115 = load i32, ptr %5, align 4
  ret i32 %115
}

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

declare ptr @RAND_get0_private(ptr noundef) #2

declare ptr @BN_CTX_new_ex(ptr noundef) #2

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

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

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

declare void @BN_CTX_free(ptr noundef) #2

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 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 8}
!12 = !{!"rsa_st", !10, i64 0, !6, i64 8, !10, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !13, i64 104, !6, i64 128, !6, i64 136, !15, i64 144, !16, i64 160, !10, i64 164, !6, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !10, i64 216}
!13 = !{!"rsa_pss_params_30_st", !10, i64 0, !14, i64 4, !10, i64 12, !10, i64 16}
!14 = !{!"", !10, i64 0, !10, i64 4}
!15 = !{!"crypto_ex_data_st", !6, i64 0, !6, i64 8}
!16 = !{!"", !7, i64 0}
!17 = !{!12, !6, i64 64}
!18 = !{!12, !6, i64 72}


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

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

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

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

declare void @BN_free(ptr noundef) local_unnamed_addr #1

declare ptr @BN_new() local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @ossl_rsa_sp800_56b_generate_key(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = tail call i32 @ossl_rsa_sp800_56b_validate_strength(i32 noundef %1, i32 noundef -1)
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %42, label %6

6:                                                ; preds = %4
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %9 = tail call ptr @RAND_get0_private(ptr noundef %8) #2
  %10 = tail call i32 @rsa_validate_rng_strength(ptr noundef %9, i32 noundef %1)
  %.not42 = icmp eq i32 %10, 0
  br i1 %.not42, label %42, label %11

11:                                               ; preds = %6
  %12 = load ptr, ptr %7, align 8, !tbaa !5
  %13 = tail call ptr @BN_CTX_new_ex(ptr noundef %12) #2
  %14 = icmp eq ptr %13, null
  br i1 %14, label %42, label %15

15:                                               ; preds = %11
  %16 = icmp eq ptr %2, null
  br i1 %16, label %17, label %22

17:                                               ; preds = %15
  %18 = tail call ptr @BN_new() #2
  %19 = icmp eq ptr %18, null
  br i1 %19, label %.thread, label %20

20:                                               ; preds = %17
  %21 = tail call i32 @BN_set_word(ptr noundef nonnull %18, i64 noundef 65537) #2
  %.not43 = icmp eq i32 %21, 0
  br i1 %.not43, label %.thread, label %22

22:                                               ; preds = %15, %20
  %.036 = phi ptr [ %18, %20 ], [ %2, %15 ]
  %23 = getelementptr inbounds i8, ptr %0, i64 64
  %24 = getelementptr inbounds i8, ptr %0, i64 72
  br label %25

25:                                               ; preds = %38, %22
  %26 = tail call i32 @ossl_rsa_fips186_4_gen_prob_primes(ptr noundef nonnull %0, ptr noundef null, i32 noundef %1, ptr noundef nonnull %.036, ptr noundef nonnull %13, ptr noundef %3)
  %.not44 = icmp eq i32 %26, 0
  br i1 %.not44, label %.loopexit, label %27

27:                                               ; preds = %25
  %28 = load ptr, ptr %23, align 8, !tbaa !15
  %29 = load ptr, ptr %24, align 8, !tbaa !16
  %30 = tail call i32 @BN_cmp(ptr noundef %28, ptr noundef %29) #2
  %31 = icmp slt i32 %30, 0
  br i1 %31, label %32, label %35

32:                                               ; preds = %27
  %33 = load <2 x ptr>, ptr %23, align 8, !tbaa !17
  %34 = shufflevector <2 x ptr> %33, <2 x ptr> poison, <2 x i32> <i32 1, i32 0>
  store <2 x ptr> %34, ptr %23, align 8, !tbaa !17
  br label %35

35:                                               ; preds = %32, %27
  %36 = tail call i32 @ossl_rsa_sp800_56b_derive_params_from_pq(ptr noundef nonnull %0, i32 noundef %1, ptr noundef nonnull %.036, ptr noundef nonnull %13)
  %37 = icmp slt i32 %36, 0
  br i1 %37, label %.loopexit, label %38

38:                                               ; preds = %35
  %.not45 = icmp eq i32 %36, 0
  br i1 %.not45, label %25, label %39

39:                                               ; preds = %38
  %40 = tail call i32 @ossl_rsa_sp800_56b_pairwise_test(ptr noundef nonnull %0, ptr noundef nonnull %13)
  br label %.loopexit

.loopexit:                                        ; preds = %35, %25, %39
  %.035 = phi i32 [ %40, %39 ], [ 0, %25 ], [ 0, %35 ]
  br i1 %16, label %.thread, label %41

.thread:                                          ; preds = %20, %17, %.loopexit
  %.03550 = phi i32 [ %.035, %.loopexit ], [ 0, %17 ], [ 0, %20 ]
  %.148 = phi ptr [ %.036, %.loopexit ], [ null, %17 ], [ %18, %20 ]
  tail call void @BN_free(ptr noundef %.148) #2
  br label %41

41:                                               ; preds = %.thread, %.loopexit
  %.03549 = phi i32 [ %.03550, %.thread ], [ %.035, %.loopexit ]
  tail call void @BN_CTX_free(ptr noundef nonnull %13) #2
  br label %42

42:                                               ; preds = %11, %6, %4, %41
  %.0 = phi i32 [ %.03549, %41 ], [ 0, %4 ], [ 0, %6 ], [ 0, %11 ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden i32 @rsa_validate_rng_strength(ptr noundef, i32 noundef) local_unnamed_addr #0

declare ptr @RAND_get0_private(ptr noundef) local_unnamed_addr #1

declare ptr @BN_CTX_new_ex(ptr noundef) local_unnamed_addr #1

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

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

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

declare void @BN_CTX_free(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 = { 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, !10, i64 8}
!6 = !{!"rsa_st", !7, i64 0, !10, i64 8, !7, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !10, i64 88, !10, i64 96, !11, i64 104, !10, i64 128, !10, i64 136, !13, i64 144, !14, i64 160, !7, i64 164, !10, i64 168, !10, i64 176, !10, i64 184, !10, i64 192, !10, i64 200, !10, i64 208, !7, i64 216}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"rsa_pss_params_30_st", !7, i64 0, !12, i64 4, !7, i64 12, !7, i64 16}
!12 = !{!"", !7, i64 0, !7, i64 4}
!13 = !{!"crypto_ex_data_st", !10, i64 0, !10, i64 8}
!14 = !{!"", !8, i64 0}
!15 = !{!6, !10, i64 64}
!16 = !{!6, !10, i64 72}
!17 = !{!10, !10, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopSimplifyPass,LoopUnrollPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass