; 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.bignum_st = type opaque

@ossl_bn_inv_sqrt_2 = external constant %struct.bignum_st, align 1

; 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 ptr @BN_copy(ptr noundef, ptr noundef) #1

declare i32 @BN_cmp(ptr noundef, 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

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

21:                                               ; preds = %3
  store i32 0, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %64

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

28:                                               ; preds = %22
  br label %61

29:                                               ; preds = %22
  %30 = load ptr, ptr %9, align 8, !tbaa !5
  %31 = call ptr @BN_copy(ptr noundef %30, ptr noundef @ossl_bn_inv_sqrt_2)
  %32 = icmp ne ptr %31, null
  br i1 %32, label %34, label %33

33:                                               ; preds = %29
  br label %61

34:                                               ; preds = %29
  %35 = load i32, ptr %10, align 4, !tbaa !9
  %36 = icmp sge i32 %35, 0
  br i1 %36, label %37, label %45

37:                                               ; preds = %34
  %38 = load ptr, ptr %9, align 8, !tbaa !5
  %39 = load ptr, ptr %9, align 8, !tbaa !5
  %40 = load i32, ptr %10, align 4, !tbaa !9
  %41 = call i32 @BN_lshift(ptr noundef %38, ptr noundef %39, i32 noundef %40)
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %44, label %43

43:                                               ; preds = %37
  br label %61

44:                                               ; preds = %37
  br label %54

45:                                               ; preds = %34
  %46 = load ptr, ptr %9, align 8, !tbaa !5
  %47 = load ptr, ptr %9, align 8, !tbaa !5
  %48 = load i32, ptr %10, align 4, !tbaa !9
  %49 = sub nsw i32 0, %48
  %50 = call i32 @BN_rshift(ptr noundef %46, ptr noundef %47, i32 noundef %49)
  %51 = icmp ne i32 %50, 0
  br i1 %51, label %53, label %52

52:                                               ; preds = %45
  br label %61

53:                                               ; preds = %45
  br label %54

54:                                               ; preds = %53, %44
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = load ptr, ptr %9, align 8, !tbaa !5
  %57 = call i32 @BN_cmp(ptr noundef %55, ptr noundef %56)
  %58 = icmp sle i32 %57, 0
  br i1 %58, label %59, label %60

59:                                               ; preds = %54
  br label %61

60:                                               ; preds = %54
  store i32 1, ptr %8, align 4, !tbaa !9
  br label %61

61:                                               ; preds = %60, %59, %52, %43, %33, %28
  %62 = load ptr, ptr %7, align 8, !tbaa !5
  call void @BN_CTX_end(ptr noundef %62)
  %63 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %63, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %64

64:                                               ; preds = %61, %21
  call void @llvm.lifetime.end.p0(i64 4, 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
  %65 = load i32, ptr %4, align 4
  ret i32 %65
}

declare i32 @BN_num_bits(ptr noundef) #1

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

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

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}


; 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.bignum_st = type opaque

@ossl_bn_inv_sqrt_2 = external constant %struct.bignum_st, align 1

declare void @BN_CTX_start(ptr noundef) local_unnamed_addr #0

declare ptr @BN_CTX_get(ptr noundef) local_unnamed_addr #0

declare ptr @BN_copy(ptr noundef, ptr noundef) local_unnamed_addr #0

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

declare void @BN_CTX_end(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @ossl_rsa_check_prime_factor_range(ptr noundef %0, i32 noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = ashr i32 %1, 1
  %5 = tail call i32 @BN_num_bits(ptr noundef nonnull @ossl_bn_inv_sqrt_2) #2
  %6 = sub nsw i32 %4, %5
  %7 = tail call i32 @BN_num_bits(ptr noundef %0) #2
  %.not = icmp eq i32 %7, %4
  br i1 %.not, label %8, label %24

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 = icmp eq ptr %9, null
  br i1 %10, label %23, label %11

11:                                               ; preds = %8
  %12 = tail call ptr @BN_copy(ptr noundef nonnull %9, ptr noundef nonnull @ossl_bn_inv_sqrt_2) #2
  %.not22 = icmp eq ptr %12, null
  br i1 %.not22, label %23, label %13

13:                                               ; preds = %11
  %14 = icmp sgt i32 %6, -1
  br i1 %14, label %15, label %17

15:                                               ; preds = %13
  %16 = tail call i32 @BN_lshift(ptr noundef nonnull %9, ptr noundef nonnull %9, i32 noundef %6) #2
  %.not24 = icmp eq i32 %16, 0
  br i1 %.not24, label %23, label %20

17:                                               ; preds = %13
  %18 = sub nsw i32 0, %6
  %19 = tail call i32 @BN_rshift(ptr noundef nonnull %9, ptr noundef nonnull %9, i32 noundef %18) #2
  %.not23 = icmp eq i32 %19, 0
  br i1 %.not23, label %23, label %20

20:                                               ; preds = %17, %15
  %21 = tail call i32 @BN_cmp(ptr noundef %0, ptr noundef nonnull %9) #2
  %22 = icmp sgt i32 %21, 0
  %spec.select = zext i1 %22 to i32
  br label %23

23:                                               ; preds = %20, %17, %15, %11, %8
  %.019 = phi i32 [ 0, %8 ], [ 0, %15 ], [ 0, %17 ], [ 0, %11 ], [ %spec.select, %20 ]
  tail call void @BN_CTX_end(ptr noundef %2) #2
  br label %24

24:                                               ; preds = %3, %23
  %.0 = phi i32 [ %.019, %23 ], [ 0, %3 ]
  ret i32 %.0
}

declare i32 @BN_num_bits(ptr noundef) local_unnamed_addr #0

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

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

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)"}


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