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

; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

declare void @BN_CTX_start(ptr noundef) #1

declare ptr @BN_CTX_get(ptr noundef) #1

declare void @BN_set_flags(ptr noundef, i32 noundef) #1

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

declare i32 @BN_mod_mul(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #1

declare i32 @BN_is_one(ptr noundef) #1

declare void @BN_clear(ptr noundef) #1

declare void @BN_CTX_end(ptr noundef) #1

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

declare i32 @BN_num_bits(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @ossl_rsa_check_private_exponent(ptr noundef %0, i32 noundef %1, ptr noundef %2) #2 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.rsa_st, ptr %16, i32 0, i32 7
  %18 = load ptr, ptr %17, align 8, !tbaa !11
  %19 = call i32 @BN_num_bits(ptr noundef %18)
  %20 = load i32, ptr %6, align 4, !tbaa !9
  %21 = ashr i32 %20, 1
  %22 = icmp sle i32 %19, %21
  br i1 %22, label %23, label %24

23:                                               ; preds = %3
  store i32 0, ptr %4, align 4
  store i32 1, ptr %15, align 4
  br label %99

24:                                               ; preds = %3
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  call void @BN_CTX_start(ptr noundef %25)
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = call ptr @BN_CTX_get(ptr noundef %26)
  store ptr %27, ptr %9, align 8, !tbaa !5
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = call ptr @BN_CTX_get(ptr noundef %28)
  store ptr %29, ptr %10, align 8, !tbaa !5
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = call ptr @BN_CTX_get(ptr noundef %30)
  store ptr %31, ptr %11, align 8, !tbaa !5
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = call ptr @BN_CTX_get(ptr noundef %32)
  store ptr %33, ptr %12, align 8, !tbaa !5
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = call ptr @BN_CTX_get(ptr noundef %34)
  store ptr %35, ptr %13, align 8, !tbaa !5
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = call ptr @BN_CTX_get(ptr noundef %36)
  store ptr %37, ptr %14, align 8, !tbaa !5
  %38 = load ptr, ptr %14, align 8, !tbaa !5
  %39 = icmp ne ptr %38, null
  br i1 %39, label %40, label %47

40:                                               ; preds = %24
  %41 = load ptr, ptr %9, align 8, !tbaa !5
  call void @BN_set_flags(ptr noundef %41, i32 noundef 4)
  %42 = load ptr, ptr %10, align 8, !tbaa !5
  call void @BN_set_flags(ptr noundef %42, i32 noundef 4)
  %43 = load ptr, ptr %11, align 8, !tbaa !5
  call void @BN_set_flags(ptr noundef %43, i32 noundef 4)
  %44 = load ptr, ptr %12, align 8, !tbaa !5
  call void @BN_set_flags(ptr noundef %44, i32 noundef 4)
  %45 = load ptr, ptr %13, align 8, !tbaa !5
  call void @BN_set_flags(ptr noundef %45, i32 noundef 4)
  %46 = load ptr, ptr %14, align 8, !tbaa !5
  call void @BN_set_flags(ptr noundef %46, i32 noundef 4)
  store i32 1, ptr %8, align 4, !tbaa !9
  br label %48

47:                                               ; preds = %24
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %48

48:                                               ; preds = %47, %40
  %49 = load i32, ptr %8, align 4, !tbaa !9
  %50 = icmp ne i32 %49, 0
  br i1 %50, label %51, label %89

51:                                               ; preds = %48
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.rsa_st, ptr %53, i32 0, i32 8
  %55 = load ptr, ptr %54, align 8, !tbaa !17
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.rsa_st, ptr %56, i32 0, i32 9
  %58 = load ptr, ptr %57, align 8, !tbaa !18
  %59 = load ptr, ptr %12, align 8, !tbaa !5
  %60 = load ptr, ptr %14, align 8, !tbaa !5
  %61 = load ptr, ptr %10, align 8, !tbaa !5
  %62 = load ptr, ptr %11, align 8, !tbaa !5
  %63 = load ptr, ptr %13, align 8, !tbaa !5
  %64 = call i32 @ossl_rsa_get_lcm(ptr noundef %52, ptr noundef %55, ptr noundef %58, ptr noundef %59, ptr noundef %60, ptr noundef %61, ptr noundef %62, ptr noundef %63)
  %65 = icmp eq i32 %64, 1
  br i1 %65, label %66, label %89

66:                                               ; preds = %51
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.rsa_st, ptr %67, i32 0, i32 7
  %69 = load ptr, ptr %68, align 8, !tbaa !11
  %70 = load ptr, ptr %12, align 8, !tbaa !5
  %71 = call i32 @BN_cmp(ptr noundef %69, ptr noundef %70)
  %72 = icmp slt i32 %71, 0
  br i1 %72, label %73, label %89

73:                                               ; preds = %66
  %74 = load ptr, ptr %9, align 8, !tbaa !5
  %75 = load ptr, ptr %5, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.rsa_st, ptr %75, i32 0, i32 6
  %77 = load ptr, ptr %76, align 8, !tbaa !19
  %78 = load ptr, ptr %5, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.rsa_st, ptr %78, i32 0, i32 7
  %80 = load ptr, ptr %79, align 8, !tbaa !11
  %81 = load ptr, ptr %12, align 8, !tbaa !5
  %82 = load ptr, ptr %7, align 8, !tbaa !5
  %83 = call i32 @BN_mod_mul(ptr noundef %74, ptr noundef %77, ptr noundef %80, ptr noundef %81, ptr noundef %82)
  %84 = icmp ne i32 %83, 0
  br i1 %84, label %85, label %89

85:                                               ; preds = %73
  %86 = load ptr, ptr %9, align 8, !tbaa !5
  %87 = call i32 @BN_is_one(ptr noundef %86)
  %88 = icmp ne i32 %87, 0
  br label %89

89:                                               ; preds = %85, %73, %66, %51, %48
  %90 = phi i1 [ false, %73 ], [ false, %66 ], [ false, %51 ], [ false, %48 ], [ %88, %85 ]
  %91 = zext i1 %90 to i32
  store i32 %91, ptr %8, align 4, !tbaa !9
  %92 = load ptr, ptr %9, align 8, !tbaa !5
  call void @BN_clear(ptr noundef %92)
  %93 = load ptr, ptr %10, align 8, !tbaa !5
  call void @BN_clear(ptr noundef %93)
  %94 = load ptr, ptr %11, align 8, !tbaa !5
  call void @BN_clear(ptr noundef %94)
  %95 = load ptr, ptr %12, align 8, !tbaa !5
  call void @BN_clear(ptr noundef %95)
  %96 = load ptr, ptr %14, align 8, !tbaa !5
  call void @BN_clear(ptr noundef %96)
  %97 = load ptr, ptr %7, align 8, !tbaa !5
  call void @BN_CTX_end(ptr noundef %97)
  %98 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %98, ptr %4, align 4
  store i32 1, ptr %15, align 4
  br label %99

99:                                               ; preds = %89, %23
  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 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %100 = load i32, ptr %4, align 4
  ret i32 %100
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 }

!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 56}
!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, !6, i64 48}


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

declare void @BN_CTX_start(ptr noundef) local_unnamed_addr #0

declare ptr @BN_CTX_get(ptr noundef) local_unnamed_addr #0

declare void @BN_set_flags(ptr noundef, i32 noundef) local_unnamed_addr #0

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

declare i32 @BN_mod_mul(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

declare i32 @BN_is_one(ptr noundef) local_unnamed_addr #0

declare void @BN_clear(ptr noundef) local_unnamed_addr #0

declare void @BN_CTX_end(ptr noundef) local_unnamed_addr #0

declare i32 @BN_num_bits(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @ossl_rsa_check_private_exponent(ptr nocapture noundef readonly %0, i32 noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = getelementptr inbounds i8, ptr %0, i64 56
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = tail call i32 @BN_num_bits(ptr noundef %5) #2
  %7 = ashr i32 %1, 1
  %.not = icmp sgt i32 %6, %7
  br i1 %.not, label %8, label %36

8:                                                ; preds = %3
  tail call void @BN_CTX_start(ptr noundef %2) #2
  %9 = tail call ptr @BN_CTX_get(ptr noundef %2) #2
  %10 = tail call ptr @BN_CTX_get(ptr noundef %2) #2
  %11 = tail call ptr @BN_CTX_get(ptr noundef %2) #2
  %12 = tail call ptr @BN_CTX_get(ptr noundef %2) #2
  %13 = tail call ptr @BN_CTX_get(ptr noundef %2) #2
  %14 = tail call ptr @BN_CTX_get(ptr noundef %2) #2
  %.not42 = icmp eq ptr %14, null
  br i1 %.not42, label %.critedge, label %15

15:                                               ; preds = %8
  tail call void @BN_set_flags(ptr noundef %9, i32 noundef 4) #2
  tail call void @BN_set_flags(ptr noundef %10, i32 noundef 4) #2
  tail call void @BN_set_flags(ptr noundef %11, i32 noundef 4) #2
  tail call void @BN_set_flags(ptr noundef %12, i32 noundef 4) #2
  tail call void @BN_set_flags(ptr noundef %13, i32 noundef 4) #2
  tail call void @BN_set_flags(ptr noundef nonnull %14, i32 noundef 4) #2
  %16 = getelementptr inbounds i8, ptr %0, i64 64
  %17 = load ptr, ptr %16, align 8, !tbaa !15
  %18 = getelementptr inbounds i8, ptr %0, i64 72
  %19 = load ptr, ptr %18, align 8, !tbaa !16
  %20 = tail call i32 @ossl_rsa_get_lcm(ptr noundef %2, ptr noundef %17, ptr noundef %19, ptr noundef %12, ptr noundef nonnull %14, ptr noundef %10, ptr noundef %11, ptr noundef %13)
  %21 = icmp eq i32 %20, 1
  br i1 %21, label %22, label %.critedge

22:                                               ; preds = %15
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = tail call i32 @BN_cmp(ptr noundef %23, ptr noundef %12) #2
  %25 = icmp slt i32 %24, 0
  br i1 %25, label %26, label %.critedge

26:                                               ; preds = %22
  %27 = getelementptr inbounds i8, ptr %0, i64 48
  %28 = load ptr, ptr %27, align 8, !tbaa !17
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = tail call i32 @BN_mod_mul(ptr noundef %9, ptr noundef %28, ptr noundef %29, ptr noundef %12, ptr noundef %2) #2
  %.not44 = icmp eq i32 %30, 0
  br i1 %.not44, label %.critedge, label %31

31:                                               ; preds = %26
  %32 = tail call i32 @BN_is_one(ptr noundef %9) #2
  %33 = icmp ne i32 %32, 0
  %34 = zext i1 %33 to i32
  br label %.critedge

.critedge:                                        ; preds = %8, %31, %26, %22, %15
  %35 = phi i32 [ 0, %26 ], [ 0, %22 ], [ 0, %15 ], [ %34, %31 ], [ 0, %8 ]
  tail call void @BN_clear(ptr noundef %9) #2
  tail call void @BN_clear(ptr noundef %10) #2
  tail call void @BN_clear(ptr noundef %11) #2
  tail call void @BN_clear(ptr noundef %12) #2
  tail call void @BN_clear(ptr noundef %14) #2
  tail call void @BN_CTX_end(ptr noundef %2) #2
  br label %36

36:                                               ; preds = %3, %.critedge
  %.0 = phi i32 [ %35, %.critedge ], [ 0, %3 ]
  ret i32 %.0
}

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

attributes #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 = { 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 = { 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 56}
!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, !10, i64 48}


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