; LLVM IR from ARMmbed/mbed-crypto :: library (rsa)

; 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.mbedtls_rsa_context = type { i32, i64, %struct.mbedtls_mpi, %struct.mbedtls_mpi, %struct.mbedtls_mpi, %struct.mbedtls_mpi, %struct.mbedtls_mpi, %struct.mbedtls_mpi, %struct.mbedtls_mpi, %struct.mbedtls_mpi, %struct.mbedtls_mpi, %struct.mbedtls_mpi, %struct.mbedtls_mpi, %struct.mbedtls_mpi, %struct.mbedtls_mpi, i32, i32 }
%struct.mbedtls_mpi = type { i32, i64, ptr }

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

declare i64 @mbedtls_mpi_bitlen(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @mbedtls_rsa_check_pubkey(ptr noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  br label %4

4:                                                ; preds = %1
  br label %5

5:                                                ; preds = %4
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = call i32 @rsa_check_context(ptr noundef %6, i32 noundef 0, i32 noundef 0)
  %8 = icmp ne i32 %7, 0
  br i1 %8, label %9, label %10

9:                                                ; preds = %5
  store i32 -16896, ptr %2, align 4
  br label %35

10:                                               ; preds = %5
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %11, i32 0, i32 2
  %13 = call i64 @mbedtls_mpi_bitlen(ptr noundef %12)
  %14 = icmp ult i64 %13, 128
  br i1 %14, label %15, label %16

15:                                               ; preds = %10
  store i32 -16896, ptr %2, align 4
  br label %35

16:                                               ; preds = %10
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %17, i32 0, i32 3
  %19 = call i32 @mbedtls_mpi_get_bit(ptr noundef %18, i64 noundef 0)
  %20 = icmp eq i32 %19, 0
  br i1 %20, label %33, label %21

21:                                               ; preds = %16
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %22, i32 0, i32 3
  %24 = call i64 @mbedtls_mpi_bitlen(ptr noundef %23)
  %25 = icmp ult i64 %24, 2
  br i1 %25, label %33, label %26

26:                                               ; preds = %21
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %27, i32 0, i32 3
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.mbedtls_rsa_context, ptr %29, i32 0, i32 2
  %31 = call i32 @mbedtls_mpi_cmp_mpi(ptr noundef %28, ptr noundef %30)
  %32 = icmp sge i32 %31, 0
  br i1 %32, label %33, label %34

33:                                               ; preds = %26, %21, %16
  store i32 -16896, ptr %2, align 4
  br label %35

34:                                               ; preds = %26
  store i32 0, ptr %2, align 4
  br label %35

35:                                               ; preds = %34, %33, %15, %9
  %36 = load i32, ptr %2, align 4
  ret i32 %36
}

declare i32 @mbedtls_mpi_get_bit(ptr noundef, i64 noundef) #1

declare i32 @mbedtls_mpi_cmp_mpi(ptr noundef, ptr noundef) #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" }

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


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

declare i64 @mbedtls_mpi_bitlen(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i32 -16896, 1) i32 @mbedtls_rsa_check_pubkey(ptr noundef %0) local_unnamed_addr #0 {
  %2 = tail call i32 @rsa_check_context(ptr noundef %0, i32 noundef 0, i32 noundef 0)
  %.not = icmp eq i32 %2, 0
  br i1 %.not, label %3, label %16

3:                                                ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  %5 = tail call i64 @mbedtls_mpi_bitlen(ptr noundef nonnull %4) #2
  %6 = icmp ult i64 %5, 128
  br i1 %6, label %16, label %7

7:                                                ; preds = %3
  %8 = getelementptr inbounds i8, ptr %0, i64 40
  %9 = tail call i32 @mbedtls_mpi_get_bit(ptr noundef nonnull %8, i64 noundef 0) #2
  %10 = icmp eq i32 %9, 0
  br i1 %10, label %16, label %11

11:                                               ; preds = %7
  %12 = tail call i64 @mbedtls_mpi_bitlen(ptr noundef nonnull %8) #2
  %13 = icmp ult i64 %12, 2
  br i1 %13, label %16, label %14

14:                                               ; preds = %11
  %15 = tail call i32 @mbedtls_mpi_cmp_mpi(ptr noundef nonnull %8, ptr noundef nonnull %4) #2
  %.inv = icmp slt i32 %15, 0
  %spec.select = select i1 %.inv, i32 0, i32 -16896
  br label %16

16:                                               ; preds = %14, %7, %11, %3, %1
  %.0 = phi i32 [ -16896, %1 ], [ -16896, %3 ], [ -16896, %11 ], [ -16896, %7 ], [ %spec.select, %14 ]
  ret i32 %.0
}

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

declare i32 @mbedtls_mpi_cmp_mpi(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)"}


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