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

; 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 @RSA_X931_derive_ex(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr 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

declare ptr @BN_CTX_new_ex(ptr noundef) #2

declare void @BN_CTX_start(ptr noundef) #2

declare ptr @BN_CTX_get(ptr noundef) #2

declare ptr @BN_new() #2

declare void @BN_CTX_end(ptr noundef) #2

declare void @BN_CTX_free(ptr noundef) #2

; 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
define dso_local i32 @RSA_X931_generate_key_ex(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 ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = 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 8, ptr %11) #3
  store ptr null, ptr %11, align 8, !tbaa !5
  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
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.rsa_st, ptr %15, i32 0, i32 1
  %17 = load ptr, ptr %16, align 8, !tbaa !11
  %18 = call ptr @BN_CTX_new_ex(ptr noundef %17)
  store ptr %18, ptr %13, align 8, !tbaa !5
  %19 = load ptr, ptr %13, align 8, !tbaa !5
  %20 = icmp eq ptr %19, null
  br i1 %20, label %21, label %22

21:                                               ; preds = %4
  br label %90

22:                                               ; preds = %4
  %23 = load ptr, ptr %13, align 8, !tbaa !5
  call void @BN_CTX_start(ptr noundef %23)
  %24 = load ptr, ptr %13, align 8, !tbaa !5
  %25 = call ptr @BN_CTX_get(ptr noundef %24)
  store ptr %25, ptr %11, align 8, !tbaa !5
  %26 = load ptr, ptr %13, align 8, !tbaa !5
  %27 = call ptr @BN_CTX_get(ptr noundef %26)
  store ptr %27, ptr %12, align 8, !tbaa !5
  %28 = load ptr, ptr %12, align 8, !tbaa !5
  %29 = icmp eq ptr %28, null
  br i1 %29, label %30, label %31

30:                                               ; preds = %22
  br label %90

31:                                               ; preds = %22
  %32 = load ptr, ptr %11, align 8, !tbaa !5
  %33 = load ptr, ptr %12, align 8, !tbaa !5
  %34 = load i32, ptr %7, align 4, !tbaa !9
  %35 = load ptr, ptr %13, align 8, !tbaa !5
  %36 = call i32 @BN_X931_generate_Xpq(ptr noundef %32, ptr noundef %33, i32 noundef %34, ptr noundef %35)
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %39, label %38

38:                                               ; preds = %31
  br label %90

39:                                               ; preds = %31
  %40 = call ptr @BN_new()
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.rsa_st, ptr %41, i32 0, i32 8
  store ptr %40, ptr %42, align 8, !tbaa !17
  %43 = call ptr @BN_new()
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.rsa_st, ptr %44, i32 0, i32 9
  store ptr %43, ptr %45, align 8, !tbaa !18
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.rsa_st, ptr %46, i32 0, i32 8
  %48 = load ptr, ptr %47, align 8, !tbaa !17
  %49 = icmp eq ptr %48, null
  br i1 %49, label %55, label %50

50:                                               ; preds = %39
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.rsa_st, ptr %51, i32 0, i32 9
  %53 = load ptr, ptr %52, align 8, !tbaa !18
  %54 = icmp eq ptr %53, null
  br i1 %54, label %55, label %56

55:                                               ; preds = %50, %39
  br label %90

56:                                               ; preds = %50
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.rsa_st, ptr %57, i32 0, i32 8
  %59 = load ptr, ptr %58, align 8, !tbaa !17
  %60 = load ptr, ptr %11, align 8, !tbaa !5
  %61 = load ptr, ptr %8, align 8, !tbaa !5
  %62 = load ptr, ptr %13, align 8, !tbaa !5
  %63 = load ptr, ptr %9, align 8, !tbaa !5
  %64 = call i32 @BN_X931_generate_prime_ex(ptr noundef %59, ptr noundef null, ptr noundef null, ptr noundef null, ptr noundef null, ptr noundef %60, ptr noundef %61, ptr noundef %62, ptr noundef %63)
  %65 = icmp ne i32 %64, 0
  br i1 %65, label %67, label %66

66:                                               ; preds = %56
  br label %90

67:                                               ; preds = %56
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.rsa_st, ptr %68, i32 0, i32 9
  %70 = load ptr, ptr %69, align 8, !tbaa !18
  %71 = load ptr, ptr %12, align 8, !tbaa !5
  %72 = load ptr, ptr %8, align 8, !tbaa !5
  %73 = load ptr, ptr %13, align 8, !tbaa !5
  %74 = load ptr, ptr %9, align 8, !tbaa !5
  %75 = call i32 @BN_X931_generate_prime_ex(ptr noundef %70, ptr noundef null, ptr noundef null, ptr noundef null, ptr noundef null, ptr noundef %71, ptr noundef %72, ptr noundef %73, ptr noundef %74)
  %76 = icmp ne i32 %75, 0
  br i1 %76, label %78, label %77

77:                                               ; preds = %67
  br label %90

78:                                               ; preds = %67
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  %80 = load ptr, ptr %8, align 8, !tbaa !5
  %81 = load ptr, ptr %9, align 8, !tbaa !5
  %82 = call i32 @RSA_X931_derive_ex(ptr noundef %79, ptr noundef null, ptr noundef null, ptr noundef null, ptr noundef null, ptr noundef null, ptr noundef null, ptr noundef null, ptr noundef null, ptr noundef null, ptr noundef null, ptr noundef %80, ptr noundef %81)
  %83 = icmp ne i32 %82, 0
  br i1 %83, label %85, label %84

84:                                               ; preds = %78
  br label %90

85:                                               ; preds = %78
  %86 = load ptr, ptr %6, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.rsa_st, ptr %86, i32 0, i32 25
  %88 = load i32, ptr %87, align 8, !tbaa !19
  %89 = add nsw i32 %88, 1
  store i32 %89, ptr %87, align 8, !tbaa !19
  store i32 1, ptr %10, align 4, !tbaa !9
  br label %90

90:                                               ; preds = %85, %84, %77, %66, %55, %38, %30, %21
  %91 = load ptr, ptr %13, align 8, !tbaa !5
  call void @BN_CTX_end(ptr noundef %91)
  %92 = load ptr, ptr %13, align 8, !tbaa !5
  call void @BN_CTX_free(ptr noundef %92)
  %93 = load i32, ptr %10, align 4, !tbaa !9
  %94 = icmp ne i32 %93, 0
  br i1 %94, label %95, label %96

95:                                               ; preds = %90
  store i32 1, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %97

96:                                               ; preds = %90
  store i32 0, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %97

97:                                               ; preds = %96, %95
  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 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %98 = load i32, ptr %5, align 4
  ret i32 %98
}

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

declare i32 @BN_X931_generate_prime_ex(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, 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}
!19 = !{!12, !10, i64 216}


; 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 @RSA_X931_derive_ex(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

declare ptr @BN_CTX_new_ex(ptr noundef) local_unnamed_addr #1

declare void @BN_CTX_start(ptr noundef) local_unnamed_addr #1

declare ptr @BN_CTX_get(ptr noundef) local_unnamed_addr #1

declare ptr @BN_new() local_unnamed_addr #1

declare void @BN_CTX_end(ptr noundef) local_unnamed_addr #1

declare void @BN_CTX_free(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @RSA_X931_generate_key_ex(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = tail call ptr @BN_CTX_new_ex(ptr noundef %6) #2
  %8 = icmp eq ptr %7, null
  br i1 %8, label %34, label %9

9:                                                ; preds = %4
  tail call void @BN_CTX_start(ptr noundef nonnull %7) #2
  %10 = tail call ptr @BN_CTX_get(ptr noundef nonnull %7) #2
  %11 = tail call ptr @BN_CTX_get(ptr noundef nonnull %7) #2
  %12 = icmp eq ptr %11, null
  br i1 %12, label %34, label %13

13:                                               ; preds = %9
  %14 = tail call i32 @BN_X931_generate_Xpq(ptr noundef %10, ptr noundef nonnull %11, i32 noundef %1, ptr noundef nonnull %7) #2
  %.not = icmp eq i32 %14, 0
  br i1 %.not, label %34, label %15

15:                                               ; preds = %13
  %16 = tail call ptr @BN_new() #2
  %17 = getelementptr inbounds i8, ptr %0, i64 64
  store ptr %16, ptr %17, align 8, !tbaa !15
  %18 = tail call ptr @BN_new() #2
  %19 = getelementptr inbounds i8, ptr %0, i64 72
  store ptr %18, ptr %19, align 8, !tbaa !16
  %20 = load ptr, ptr %17, align 8, !tbaa !15
  %21 = icmp eq ptr %20, null
  %22 = icmp eq ptr %18, null
  %or.cond = select i1 %21, i1 true, i1 %22
  br i1 %or.cond, label %34, label %23

23:                                               ; preds = %15
  %24 = tail call i32 @BN_X931_generate_prime_ex(ptr noundef nonnull %20, ptr noundef null, ptr noundef null, ptr noundef null, ptr noundef null, ptr noundef %10, ptr noundef %2, ptr noundef nonnull %7, ptr noundef %3) #2
  %.not35 = icmp eq i32 %24, 0
  br i1 %.not35, label %34, label %25

25:                                               ; preds = %23
  %26 = load ptr, ptr %19, align 8, !tbaa !16
  %27 = tail call i32 @BN_X931_generate_prime_ex(ptr noundef %26, ptr noundef null, ptr noundef null, ptr noundef null, ptr noundef null, ptr noundef nonnull %11, ptr noundef %2, ptr noundef nonnull %7, ptr noundef %3) #2
  %.not36 = icmp eq i32 %27, 0
  br i1 %.not36, label %34, label %28

28:                                               ; preds = %25
  %29 = tail call i32 @RSA_X931_derive_ex(ptr noundef nonnull %0, ptr noundef null, ptr noundef null, ptr noundef null, ptr noundef null, ptr noundef null, ptr noundef null, ptr noundef null, ptr noundef null, ptr noundef null, ptr noundef null, ptr noundef %2, ptr noundef %3)
  %.not37 = icmp eq i32 %29, 0
  br i1 %.not37, label %34, label %30

30:                                               ; preds = %28
  %31 = getelementptr inbounds i8, ptr %0, i64 216
  %32 = load i32, ptr %31, align 8, !tbaa !17
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr %31, align 8, !tbaa !17
  br label %34

34:                                               ; preds = %28, %25, %23, %15, %13, %9, %4, %30
  %not..not38 = phi i32 [ 0, %4 ], [ 0, %9 ], [ 0, %15 ], [ 1, %30 ], [ 0, %28 ], [ 0, %25 ], [ 0, %23 ], [ 0, %13 ]
  tail call void @BN_CTX_end(ptr noundef %7) #2
  tail call void @BN_CTX_free(ptr noundef %7) #2
  ret i32 %not..not38
}

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

declare i32 @BN_X931_generate_prime_ex(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, 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 = { 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 = !{!6, !7, i64 216}


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