; LLVM IR from openssl/openssl :: providers/common (securitycheck)

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

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

; 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_dh_check_key(ptr noundef %0) #2 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = icmp eq ptr %9, null
  br i1 %10, label %11, label %12

11:                                               ; preds = %1
  store i32 0, ptr %2, align 4
  store i32 1, ptr %8, align 4
  br label %52

12:                                               ; preds = %1
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = call ptr @DH_get0_p(ptr noundef %13)
  store ptr %14, ptr %6, align 8, !tbaa !5
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = call ptr @DH_get0_q(ptr noundef %15)
  store ptr %16, ptr %7, align 8, !tbaa !5
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = icmp eq ptr %17, null
  br i1 %18, label %22, label %19

19:                                               ; preds = %12
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = icmp eq ptr %20, null
  br i1 %21, label %22, label %23

22:                                               ; preds = %19, %12
  store i32 0, ptr %2, align 4
  store i32 1, ptr %8, align 4
  br label %52

23:                                               ; preds = %19
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = call i32 @BN_num_bits(ptr noundef %24)
  %26 = sext i32 %25 to i64
  store i64 %26, ptr %4, align 8, !tbaa !9
  %27 = load i64, ptr %4, align 8, !tbaa !9
  %28 = icmp ult i64 %27, 2048
  br i1 %28, label %29, label %30

29:                                               ; preds = %23
  store i32 0, ptr %2, align 4
  store i32 1, ptr %8, align 4
  br label %52

30:                                               ; preds = %23
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = call i32 @DH_get_nid(ptr noundef %31)
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %34, label %35

34:                                               ; preds = %30
  store i32 1, ptr %2, align 4
  store i32 1, ptr %8, align 4
  br label %52

35:                                               ; preds = %30
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = call i32 @BN_num_bits(ptr noundef %36)
  %38 = sext i32 %37 to i64
  store i64 %38, ptr %5, align 8, !tbaa !9
  %39 = load i64, ptr %4, align 8, !tbaa !9
  %40 = icmp eq i64 %39, 2048
  br i1 %40, label %41, label %49

41:                                               ; preds = %35
  %42 = load i64, ptr %5, align 8, !tbaa !9
  %43 = icmp eq i64 %42, 224
  br i1 %43, label %47, label %44

44:                                               ; preds = %41
  %45 = load i64, ptr %5, align 8, !tbaa !9
  %46 = icmp eq i64 %45, 256
  br label %47

47:                                               ; preds = %44, %41
  %48 = phi i1 [ true, %41 ], [ %46, %44 ]
  br label %49

49:                                               ; preds = %47, %35
  %50 = phi i1 [ false, %35 ], [ %48, %47 ]
  %51 = zext i1 %50 to i32
  store i32 %51, ptr %2, align 4
  store i32 1, ptr %8, align 4
  br label %52

52:                                               ; preds = %49, %34, %29, %22, %11
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %53 = load i32, ptr %2, align 4
  ret i32 %53
}

declare ptr @DH_get0_p(ptr noundef) #1

declare ptr @DH_get0_q(ptr noundef) #1

declare i32 @DH_get_nid(ptr 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 = !{!"long", !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"

declare i32 @BN_num_bits(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @ossl_dh_check_key(ptr noundef %0) local_unnamed_addr #1 {
  %2 = icmp eq ptr %0, null
  br i1 %2, label %20, label %3

3:                                                ; preds = %1
  %4 = tail call ptr @DH_get0_p(ptr noundef nonnull %0) #2
  %5 = tail call ptr @DH_get0_q(ptr noundef nonnull %0) #2
  %6 = icmp eq ptr %4, null
  %7 = icmp eq ptr %5, null
  %or.cond = select i1 %6, i1 true, i1 %7
  br i1 %or.cond, label %20, label %8

8:                                                ; preds = %3
  %9 = tail call i32 @BN_num_bits(ptr noundef nonnull %4) #2
  %10 = icmp ult i32 %9, 2048
  br i1 %10, label %20, label %11

11:                                               ; preds = %8
  %12 = tail call i32 @DH_get_nid(ptr noundef nonnull %0) #2
  %.not = icmp eq i32 %12, 0
  br i1 %.not, label %13, label %20

13:                                               ; preds = %11
  %14 = tail call i32 @BN_num_bits(ptr noundef nonnull %5) #2
  %15 = icmp eq i32 %9, 2048
  %16 = icmp eq i32 %14, 224
  %17 = icmp eq i32 %14, 256
  %18 = or i1 %16, %17
  %narrow = select i1 %15, i1 %18, i1 false
  %19 = zext i1 %narrow to i32
  br label %20

20:                                               ; preds = %11, %8, %3, %1, %13
  %.0 = phi i32 [ %19, %13 ], [ 0, %1 ], [ 0, %3 ], [ 0, %8 ], [ 1, %11 ]
  ret i32 %.0
}

declare ptr @DH_get0_p(ptr noundef) local_unnamed_addr #0

declare ptr @DH_get0_q(ptr noundef) local_unnamed_addr #0

declare i32 @DH_get_nid(ptr 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: CorrelatedValuePropagationPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass