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

; 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_pk_context = type { ptr, ptr }
%struct.mbedtls_pk_rsassa_pss_options = type { i32, i32 }

; 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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @mbedtls_pk_verify_ext(i32 noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, ptr noundef %4, i64 noundef %5, ptr noundef %6, i64 noundef %7) #1 {
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca ptr, align 8
  %15 = alloca i64, align 8
  %16 = alloca ptr, align 8
  %17 = alloca i64, align 8
  %18 = alloca i32, align 4
  %19 = alloca ptr, align 8
  %20 = alloca i32, align 4
  store i32 %0, ptr %10, align 4, !tbaa !5
  store ptr %1, ptr %11, align 8, !tbaa !9
  store ptr %2, ptr %12, align 8, !tbaa !9
  store i32 %3, ptr %13, align 4, !tbaa !5
  store ptr %4, ptr %14, align 8, !tbaa !9
  store i64 %5, ptr %15, align 8, !tbaa !11
  store ptr %6, ptr %16, align 8, !tbaa !9
  store i64 %7, ptr %17, align 8, !tbaa !11
  br label %21

21:                                               ; preds = %8
  br label %22

22:                                               ; preds = %21
  br label %23

23:                                               ; preds = %22
  br label %24

24:                                               ; preds = %23
  br label %25

25:                                               ; preds = %24
  br label %26

26:                                               ; preds = %25
  %27 = load ptr, ptr %12, align 8, !tbaa !9
  %28 = getelementptr inbounds %struct.mbedtls_pk_context, ptr %27, i32 0, i32 0
  %29 = load ptr, ptr %28, align 8, !tbaa !13
  %30 = icmp eq ptr %29, null
  br i1 %30, label %31, label %32

31:                                               ; preds = %26
  store i32 -16000, ptr %9, align 4
  br label %102

32:                                               ; preds = %26
  %33 = load ptr, ptr %12, align 8, !tbaa !9
  %34 = load i32, ptr %10, align 4, !tbaa !5
  %35 = call i32 @mbedtls_pk_can_do(ptr noundef %33, i32 noundef %34)
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %38, label %37

37:                                               ; preds = %32
  store i32 -16128, ptr %9, align 4
  br label %102

38:                                               ; preds = %32
  %39 = load i32, ptr %10, align 4, !tbaa !5
  %40 = icmp eq i32 %39, 6
  br i1 %40, label %41, label %90

41:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #4
  store i32 -110, ptr %18, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #4
  %42 = load i32, ptr %13, align 4, !tbaa !5
  %43 = icmp eq i32 %42, 0
  br i1 %43, label %44, label %48

44:                                               ; preds = %41
  %45 = load i64, ptr %15, align 8, !tbaa !11
  %46 = icmp ult i64 4294967295, %45
  br i1 %46, label %47, label %48

47:                                               ; preds = %44
  store i32 -16000, ptr %9, align 4
  store i32 1, ptr %20, align 4
  br label %89

48:                                               ; preds = %44, %41
  %49 = load ptr, ptr %11, align 8, !tbaa !9
  %50 = icmp eq ptr %49, null
  br i1 %50, label %51, label %52

51:                                               ; preds = %48
  store i32 -16000, ptr %9, align 4
  store i32 1, ptr %20, align 4
  br label %89

52:                                               ; preds = %48
  %53 = load ptr, ptr %11, align 8, !tbaa !9
  store ptr %53, ptr %19, align 8, !tbaa !9
  %54 = load i64, ptr %17, align 8, !tbaa !11
  %55 = load ptr, ptr %12, align 8, !tbaa !9
  %56 = call i64 @mbedtls_pk_get_len(ptr noundef %55)
  %57 = icmp ult i64 %54, %56
  br i1 %57, label %58, label %59

58:                                               ; preds = %52
  store i32 -17280, ptr %9, align 4
  store i32 1, ptr %20, align 4
  br label %89

59:                                               ; preds = %52
  %60 = load ptr, ptr %12, align 8, !tbaa !9
  %61 = getelementptr inbounds { ptr, ptr }, ptr %60, i32 0, i32 0
  %62 = load ptr, ptr %61, align 8
  %63 = getelementptr inbounds { ptr, ptr }, ptr %60, i32 0, i32 1
  %64 = load ptr, ptr %63, align 8
  %65 = call ptr @mbedtls_pk_rsa(ptr %62, ptr %64)
  %66 = load i32, ptr %13, align 4, !tbaa !5
  %67 = load i64, ptr %15, align 8, !tbaa !11
  %68 = trunc i64 %67 to i32
  %69 = load ptr, ptr %14, align 8, !tbaa !9
  %70 = load ptr, ptr %19, align 8, !tbaa !9
  %71 = getelementptr inbounds %struct.mbedtls_pk_rsassa_pss_options, ptr %70, i32 0, i32 0
  %72 = load i32, ptr %71, align 4, !tbaa !15
  %73 = load ptr, ptr %19, align 8, !tbaa !9
  %74 = getelementptr inbounds %struct.mbedtls_pk_rsassa_pss_options, ptr %73, i32 0, i32 1
  %75 = load i32, ptr %74, align 4, !tbaa !17
  %76 = load ptr, ptr %16, align 8, !tbaa !9
  %77 = call i32 @mbedtls_rsa_rsassa_pss_verify_ext(ptr noundef %65, ptr noundef null, ptr noundef null, i32 noundef 0, i32 noundef %66, i32 noundef %68, ptr noundef %69, i32 noundef %72, i32 noundef %75, ptr noundef %76)
  store i32 %77, ptr %18, align 4, !tbaa !5
  %78 = load i32, ptr %18, align 4, !tbaa !5
  %79 = icmp ne i32 %78, 0
  br i1 %79, label %80, label %82

80:                                               ; preds = %59
  %81 = load i32, ptr %18, align 4, !tbaa !5
  store i32 %81, ptr %9, align 4
  store i32 1, ptr %20, align 4
  br label %89

82:                                               ; preds = %59
  %83 = load i64, ptr %17, align 8, !tbaa !11
  %84 = load ptr, ptr %12, align 8, !tbaa !9
  %85 = call i64 @mbedtls_pk_get_len(ptr noundef %84)
  %86 = icmp ugt i64 %83, %85
  br i1 %86, label %87, label %88

87:                                               ; preds = %82
  store i32 -14592, ptr %9, align 4
  store i32 1, ptr %20, align 4
  br label %89

88:                                               ; preds = %82
  store i32 0, ptr %9, align 4
  store i32 1, ptr %20, align 4
  br label %89

89:                                               ; preds = %88, %87, %80, %58, %51, %47
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #4
  br label %102

90:                                               ; preds = %38
  %91 = load ptr, ptr %11, align 8, !tbaa !9
  %92 = icmp ne ptr %91, null
  br i1 %92, label %93, label %94

93:                                               ; preds = %90
  store i32 -16000, ptr %9, align 4
  br label %102

94:                                               ; preds = %90
  %95 = load ptr, ptr %12, align 8, !tbaa !9
  %96 = load i32, ptr %13, align 4, !tbaa !5
  %97 = load ptr, ptr %14, align 8, !tbaa !9
  %98 = load i64, ptr %15, align 8, !tbaa !11
  %99 = load ptr, ptr %16, align 8, !tbaa !9
  %100 = load i64, ptr %17, align 8, !tbaa !11
  %101 = call i32 @mbedtls_pk_verify(ptr noundef %95, i32 noundef %96, ptr noundef %97, i64 noundef %98, ptr noundef %99, i64 noundef %100)
  store i32 %101, ptr %9, align 4
  br label %102

102:                                              ; preds = %94, %93, %89, %37, %31
  %103 = load i32, ptr %9, align 4
  ret i32 %103
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @mbedtls_pk_get_len(ptr noundef) #2

declare i32 @mbedtls_rsa_rsassa_pss_verify_ext(ptr noundef, ptr noundef, ptr noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef, i32 noundef, i32 noundef, ptr noundef) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @mbedtls_pk_rsa(ptr, ptr) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { inlinehint 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 = { "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 #4 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !10, i64 0}
!14 = !{!"mbedtls_pk_context", !10, i64 0, !10, i64 8}
!15 = !{!16, !6, i64 0}
!16 = !{!"mbedtls_pk_rsassa_pss_options", !6, i64 0, !6, i64 4}
!17 = !{!16, !6, i64 4}


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

; Function Attrs: nounwind uwtable
declare dso_local i32 @mbedtls_pk_verify(ptr noundef, i32 noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @mbedtls_pk_verify_ext(i32 noundef %0, ptr noundef readonly %1, ptr noundef %2, i32 noundef %3, ptr noundef %4, i64 noundef %5, ptr noundef %6, i64 noundef %7) local_unnamed_addr #0 {
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = icmp eq ptr %9, null
  br i1 %10, label %38, label %11

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

13:                                               ; preds = %11
  %14 = icmp eq i32 %0, 6
  br i1 %14, label %15, label %35

15:                                               ; preds = %13
  %16 = icmp eq i32 %3, 0
  %17 = icmp ugt i64 %5, 4294967295
  %or.cond = and i1 %16, %17
  %18 = icmp eq ptr %1, null
  %or.cond34 = or i1 %18, %or.cond
  br i1 %or.cond34, label %38, label %19

19:                                               ; preds = %15
  %20 = tail call i64 @mbedtls_pk_get_len(ptr noundef nonnull %2)
  %21 = icmp ugt i64 %20, %7
  br i1 %21, label %38, label %22

22:                                               ; preds = %19
  %23 = load ptr, ptr %2, align 8
  %24 = getelementptr inbounds i8, ptr %2, i64 8
  %25 = load ptr, ptr %24, align 8
  %26 = tail call ptr @mbedtls_pk_rsa(ptr %23, ptr %25)
  %27 = trunc i64 %5 to i32
  %28 = load i32, ptr %1, align 4, !tbaa !10
  %29 = getelementptr inbounds i8, ptr %1, i64 4
  %30 = load i32, ptr %29, align 4, !tbaa !13
  %31 = tail call i32 @mbedtls_rsa_rsassa_pss_verify_ext(ptr noundef %26, ptr noundef null, ptr noundef null, i32 noundef 0, i32 noundef %3, i32 noundef %27, ptr noundef %4, i32 noundef %28, i32 noundef %30, ptr noundef %6) #3
  %.not33 = icmp eq i32 %31, 0
  br i1 %.not33, label %32, label %38

32:                                               ; preds = %22
  %33 = tail call i64 @mbedtls_pk_get_len(ptr noundef nonnull %2)
  %34 = icmp ult i64 %33, %7
  %. = select i1 %34, i32 -14592, i32 0
  br label %38

35:                                               ; preds = %13
  %.not32 = icmp eq ptr %1, null
  br i1 %.not32, label %36, label %38

36:                                               ; preds = %35
  %37 = tail call i32 @mbedtls_pk_verify(ptr noundef nonnull %2, i32 noundef %3, ptr noundef %4, i64 noundef %5, ptr noundef %6, i64 noundef %7)
  br label %38

38:                                               ; preds = %35, %15, %19, %22, %32, %11, %8, %36
  %.1 = phi i32 [ %37, %36 ], [ -16000, %8 ], [ -16128, %11 ], [ -16000, %15 ], [ -17280, %19 ], [ %31, %22 ], [ %., %32 ], [ -16000, %35 ]
  ret i32 %.1
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @mbedtls_pk_get_len(ptr noundef) local_unnamed_addr #1

declare i32 @mbedtls_rsa_rsassa_pss_verify_ext(ptr noundef, ptr noundef, ptr noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef, i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @mbedtls_pk_rsa(ptr, ptr) 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 = { inlinehint 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 = { "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, !7, i64 0}
!6 = !{!"mbedtls_pk_context", !7, i64 0, !7, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !12, i64 0}
!11 = !{!"mbedtls_pk_rsassa_pss_options", !12, i64 0, !12, i64 4}
!12 = !{!"int", !8, i64 0}
!13 = !{!11, !12, i64 4}


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