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

; 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.psa_global_data_t = type { ptr, ptr, %struct.mbedtls_entropy_context, %struct.mbedtls_ctr_drbg_context, i8 }
%struct.mbedtls_entropy_context = type { i32, %struct.mbedtls_sha512_context, i32, [20 x %struct.mbedtls_entropy_source_state] }
%struct.mbedtls_sha512_context = type { [2 x i64], [8 x i64], [128 x i8], i32 }
%struct.mbedtls_entropy_source_state = type { ptr, ptr, i64, i64, i32 }
%struct.mbedtls_ctr_drbg_context = type { [16 x i8], i32, i32, i64, i32, %struct.mbedtls_aes_context, ptr, ptr }
%struct.mbedtls_aes_context = type { i32, ptr, [68 x i32] }
%struct.psa_key_slot_t = type { %struct.psa_core_key_attributes_t, %union.anon }
%struct.psa_core_key_attributes_t = type { i16, i16, i32, i32, %struct.psa_key_policy_s, i16 }
%struct.psa_key_policy_s = type { i32, i32, i32 }
%union.anon = type { %struct.raw_data }
%struct.raw_data = type { ptr, i64 }

@global_data = external hidden global %struct.psa_global_data_t, align 8

; 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 hidden i32 @psa_get_key_from_slot(i16 noundef zeroext, ptr noundef, i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
declare hidden i32 @mbedtls_to_psa_error(i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @psa_asymmetric_encrypt(i16 noundef zeroext %0, i32 noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4, i64 noundef %5, ptr noundef %6, i64 noundef %7, ptr noundef %8) #1 {
  %10 = alloca i32, align 4
  %11 = alloca i16, align 2
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  %15 = alloca ptr, align 8
  %16 = alloca i64, align 8
  %17 = alloca ptr, align 8
  %18 = alloca i64, align 8
  %19 = alloca ptr, align 8
  %20 = alloca ptr, align 8
  %21 = alloca i32, align 4
  %22 = alloca i32, align 4
  %23 = alloca ptr, align 8
  %24 = alloca i32, align 4
  store i16 %0, ptr %11, align 2, !tbaa !5
  store i32 %1, ptr %12, align 4, !tbaa !9
  store ptr %2, ptr %13, align 8, !tbaa !11
  store i64 %3, ptr %14, align 8, !tbaa !13
  store ptr %4, ptr %15, align 8, !tbaa !11
  store i64 %5, ptr %16, align 8, !tbaa !13
  store ptr %6, ptr %17, align 8, !tbaa !11
  store i64 %7, ptr %18, align 8, !tbaa !13
  store ptr %8, ptr %19, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #3
  %25 = load ptr, ptr %13, align 8, !tbaa !11
  %26 = load i64, ptr %14, align 8, !tbaa !13
  %27 = load ptr, ptr %15, align 8, !tbaa !11
  %28 = load ptr, ptr %17, align 8, !tbaa !11
  %29 = load i64, ptr %18, align 8, !tbaa !13
  %30 = load ptr, ptr %19, align 8, !tbaa !11
  store i64 0, ptr %30, align 8, !tbaa !13
  %31 = load i32, ptr %12, align 4, !tbaa !9
  %32 = and i32 %31, -256
  %33 = icmp eq i32 %32, 302186496
  br i1 %33, label %38, label %34

34:                                               ; preds = %9
  %35 = load i64, ptr %16, align 8, !tbaa !13
  %36 = icmp ne i64 %35, 0
  br i1 %36, label %37, label %38

37:                                               ; preds = %34
  store i32 -135, ptr %10, align 4
  store i32 1, ptr %22, align 4
  br label %117

38:                                               ; preds = %34, %9
  %39 = load i16, ptr %11, align 2, !tbaa !5
  %40 = load i32, ptr %12, align 4, !tbaa !9
  %41 = call i32 @psa_get_key_from_slot(i16 noundef zeroext %39, ptr noundef %20, i32 noundef 256, i32 noundef %40)
  store i32 %41, ptr %21, align 4, !tbaa !9
  %42 = load i32, ptr %21, align 4, !tbaa !9
  %43 = icmp ne i32 %42, 0
  br i1 %43, label %44, label %46

44:                                               ; preds = %38
  %45 = load i32, ptr %21, align 4, !tbaa !9
  store i32 %45, ptr %10, align 4
  store i32 1, ptr %22, align 4
  br label %117

46:                                               ; preds = %38
  %47 = load ptr, ptr %20, align 8, !tbaa !11
  %48 = getelementptr inbounds %struct.psa_key_slot_t, ptr %47, i32 0, i32 0
  %49 = getelementptr inbounds %struct.psa_core_key_attributes_t, ptr %48, i32 0, i32 0
  %50 = load i16, ptr %49, align 8, !tbaa !15
  %51 = zext i16 %50 to i32
  %52 = and i32 %51, 28672
  %53 = icmp eq i32 %52, 16384
  br i1 %53, label %63, label %54

54:                                               ; preds = %46
  %55 = load ptr, ptr %20, align 8, !tbaa !11
  %56 = getelementptr inbounds %struct.psa_key_slot_t, ptr %55, i32 0, i32 0
  %57 = getelementptr inbounds %struct.psa_core_key_attributes_t, ptr %56, i32 0, i32 0
  %58 = load i16, ptr %57, align 8, !tbaa !15
  %59 = zext i16 %58 to i32
  %60 = and i32 %59, 28672
  %61 = icmp eq i32 %60, 28672
  br i1 %61, label %63, label %62

62:                                               ; preds = %54
  store i32 -135, ptr %10, align 4
  store i32 1, ptr %22, align 4
  br label %117

63:                                               ; preds = %54, %46
  %64 = load ptr, ptr %20, align 8, !tbaa !11
  %65 = getelementptr inbounds %struct.psa_key_slot_t, ptr %64, i32 0, i32 0
  %66 = getelementptr inbounds %struct.psa_core_key_attributes_t, ptr %65, i32 0, i32 0
  %67 = load i16, ptr %66, align 8, !tbaa !15
  %68 = zext i16 %67 to i32
  %69 = and i32 %68, -12289
  %70 = icmp eq i32 %69, 16385
  br i1 %70, label %71, label %116

71:                                               ; preds = %63
  call void @llvm.lifetime.start.p0(i64 8, ptr %23) #3
  %72 = load ptr, ptr %20, align 8, !tbaa !11
  %73 = getelementptr inbounds %struct.psa_key_slot_t, ptr %72, i32 0, i32 1
  %74 = load ptr, ptr %73, align 8, !tbaa !19
  store ptr %74, ptr %23, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %24) #3
  store i32 -110, ptr %24, align 4, !tbaa !9
  %75 = load i64, ptr %18, align 8, !tbaa !13
  %76 = load ptr, ptr %23, align 8, !tbaa !11
  %77 = call i64 @mbedtls_rsa_get_len(ptr noundef %76)
  %78 = icmp ult i64 %75, %77
  br i1 %78, label %79, label %80

79:                                               ; preds = %71
  store i32 -138, ptr %10, align 4
  store i32 1, ptr %22, align 4
  br label %115

80:                                               ; preds = %71
  %81 = load i32, ptr %12, align 4, !tbaa !9
  %82 = icmp eq i32 %81, 302120960
  br i1 %82, label %83, label %89

83:                                               ; preds = %80
  %84 = load ptr, ptr %23, align 8, !tbaa !11
  %85 = load i64, ptr %14, align 8, !tbaa !13
  %86 = load ptr, ptr %13, align 8, !tbaa !11
  %87 = load ptr, ptr %17, align 8, !tbaa !11
  %88 = call i32 @mbedtls_rsa_pkcs1_encrypt(ptr noundef %84, ptr noundef @mbedtls_ctr_drbg_random, ptr noundef getelementptr inbounds (%struct.psa_global_data_t, ptr @global_data, i32 0, i32 3), i32 noundef 0, i64 noundef %85, ptr noundef %86, ptr noundef %87)
  store i32 %88, ptr %24, align 4, !tbaa !9
  br label %105

89:                                               ; preds = %80
  %90 = load i32, ptr %12, align 4, !tbaa !9
  %91 = and i32 %90, -256
  %92 = icmp eq i32 %91, 302186496
  br i1 %92, label %93, label %103

93:                                               ; preds = %89
  %94 = load i32, ptr %12, align 4, !tbaa !9
  %95 = load ptr, ptr %23, align 8, !tbaa !11
  call void @psa_rsa_oaep_set_padding_mode(i32 noundef %94, ptr noundef %95)
  %96 = load ptr, ptr %23, align 8, !tbaa !11
  %97 = load ptr, ptr %15, align 8, !tbaa !11
  %98 = load i64, ptr %16, align 8, !tbaa !13
  %99 = load i64, ptr %14, align 8, !tbaa !13
  %100 = load ptr, ptr %13, align 8, !tbaa !11
  %101 = load ptr, ptr %17, align 8, !tbaa !11
  %102 = call i32 @mbedtls_rsa_rsaes_oaep_encrypt(ptr noundef %96, ptr noundef @mbedtls_ctr_drbg_random, ptr noundef getelementptr inbounds (%struct.psa_global_data_t, ptr @global_data, i32 0, i32 3), i32 noundef 0, ptr noundef %97, i64 noundef %98, i64 noundef %99, ptr noundef %100, ptr noundef %101)
  store i32 %102, ptr %24, align 4, !tbaa !9
  br label %104

103:                                              ; preds = %89
  store i32 -135, ptr %10, align 4
  store i32 1, ptr %22, align 4
  br label %115

104:                                              ; preds = %93
  br label %105

105:                                              ; preds = %104, %83
  %106 = load i32, ptr %24, align 4, !tbaa !9
  %107 = icmp eq i32 %106, 0
  br i1 %107, label %108, label %112

108:                                              ; preds = %105
  %109 = load ptr, ptr %23, align 8, !tbaa !11
  %110 = call i64 @mbedtls_rsa_get_len(ptr noundef %109)
  %111 = load ptr, ptr %19, align 8, !tbaa !11
  store i64 %110, ptr %111, align 8, !tbaa !13
  br label %112

112:                                              ; preds = %108, %105
  %113 = load i32, ptr %24, align 4, !tbaa !9
  %114 = call i32 @mbedtls_to_psa_error(i32 noundef %113)
  store i32 %114, ptr %10, align 4
  store i32 1, ptr %22, align 4
  br label %115

115:                                              ; preds = %112, %103, %79
  call void @llvm.lifetime.end.p0(i64 4, ptr %24) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %23) #3
  br label %117

116:                                              ; preds = %63
  store i32 -134, ptr %10, align 4
  store i32 1, ptr %22, align 4
  br label %117

117:                                              ; preds = %116, %115, %62, %44, %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #3
  %118 = load i32, ptr %10, align 4
  ret i32 %118
}

declare i64 @mbedtls_rsa_get_len(ptr noundef) #2

declare i32 @mbedtls_rsa_pkcs1_encrypt(ptr noundef, ptr noundef, ptr noundef, i32 noundef, i64 noundef, ptr noundef, ptr noundef) #2

declare i32 @mbedtls_ctr_drbg_random(ptr noundef, ptr noundef, i64 noundef) #2

; Function Attrs: nounwind uwtable
declare hidden void @psa_rsa_oaep_set_padding_mode(i32 noundef, ptr noundef) #1

declare i32 @mbedtls_rsa_rsaes_oaep_encrypt(ptr noundef, ptr noundef, ptr noundef, i32 noundef, ptr noundef, i64 noundef, i64 noundef, ptr noundef, ptr noundef) #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 = { "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 = !{!"short", !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, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!16, !6, i64 0}
!16 = !{!"", !17, i64 0, !7, i64 32}
!17 = !{!"", !6, i64 0, !6, i64 2, !10, i64 4, !10, i64 8, !18, i64 12, !6, i64 24}
!18 = !{!"psa_key_policy_s", !10, i64 0, !10, i64 4, !10, i64 8}
!19 = !{!7, !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.psa_global_data_t = type { ptr, ptr, %struct.mbedtls_entropy_context, %struct.mbedtls_ctr_drbg_context, i8 }
%struct.mbedtls_entropy_context = type { i32, %struct.mbedtls_sha512_context, i32, [20 x %struct.mbedtls_entropy_source_state] }
%struct.mbedtls_sha512_context = type { [2 x i64], [8 x i64], [128 x i8], i32 }
%struct.mbedtls_entropy_source_state = type { ptr, ptr, i64, i64, i32 }
%struct.mbedtls_ctr_drbg_context = type { [16 x i8], i32, i32, i64, i32, %struct.mbedtls_aes_context, ptr, ptr }
%struct.mbedtls_aes_context = type { i32, ptr, [68 x i32] }

@global_data = external hidden global %struct.psa_global_data_t, align 8

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

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

; Function Attrs: nounwind uwtable
declare hidden i32 @psa_get_key_from_slot(i16 noundef zeroext, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden i32 @mbedtls_to_psa_error(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @psa_asymmetric_encrypt(i16 noundef zeroext %0, i32 noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4, i64 noundef %5, ptr noundef %6, i64 noundef %7, ptr nocapture noundef writeonly %8) local_unnamed_addr #1 {
  %10 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %10) #3
  store i64 0, ptr %8, align 8, !tbaa !5
  %11 = and i32 %1, -256
  %12 = icmp ne i32 %11, 302186496
  %13 = icmp ne i64 %5, 0
  %or.cond = and i1 %12, %13
  br i1 %or.cond, label %42, label %14

14:                                               ; preds = %9
  %15 = call i32 @psa_get_key_from_slot(i16 noundef zeroext %0, ptr noundef nonnull %10, i32 noundef 256, i32 noundef %1)
  %.not = icmp eq i32 %15, 0
  br i1 %.not, label %16, label %42

16:                                               ; preds = %14
  %17 = load ptr, ptr %10, align 8, !tbaa !9
  %18 = load i16, ptr %17, align 8, !tbaa !11
  %19 = and i16 %18, 28672
  switch i16 %19, label %42 [
    i16 16384, label %20
    i16 28672, label %20
  ]

20:                                               ; preds = %16, %16
  %21 = and i16 %18, -12289
  %22 = icmp eq i16 %21, 16385
  br i1 %22, label %23, label %42

23:                                               ; preds = %20
  %24 = getelementptr inbounds i8, ptr %17, i64 32
  %25 = load ptr, ptr %24, align 8, !tbaa !17
  %26 = call i64 @mbedtls_rsa_get_len(ptr noundef %25) #3
  %27 = icmp ugt i64 %26, %7
  br i1 %27, label %42, label %28

28:                                               ; preds = %23
  %29 = icmp eq i32 %1, 302120960
  br i1 %29, label %30, label %32

30:                                               ; preds = %28
  %31 = call i32 @mbedtls_rsa_pkcs1_encrypt(ptr noundef %25, ptr noundef nonnull @mbedtls_ctr_drbg_random, ptr noundef nonnull getelementptr inbounds (i8, ptr @global_data, i64 1048), i32 noundef 0, i64 noundef %3, ptr noundef %2, ptr noundef %6) #3
  br label %36

32:                                               ; preds = %28
  %33 = icmp eq i32 %11, 302186496
  br i1 %33, label %34, label %42

34:                                               ; preds = %32
  call void @psa_rsa_oaep_set_padding_mode(i32 noundef %1, ptr noundef %25)
  %35 = call i32 @mbedtls_rsa_rsaes_oaep_encrypt(ptr noundef %25, ptr noundef nonnull @mbedtls_ctr_drbg_random, ptr noundef nonnull getelementptr inbounds (i8, ptr @global_data, i64 1048), i32 noundef 0, ptr noundef %4, i64 noundef %5, i64 noundef %3, ptr noundef %2, ptr noundef %6) #3
  br label %36

36:                                               ; preds = %34, %30
  %.0 = phi i32 [ %31, %30 ], [ %35, %34 ]
  %37 = icmp eq i32 %.0, 0
  br i1 %37, label %38, label %40

38:                                               ; preds = %36
  %39 = call i64 @mbedtls_rsa_get_len(ptr noundef %25) #3
  store i64 %39, ptr %8, align 8, !tbaa !5
  br label %40

40:                                               ; preds = %38, %36
  %41 = call i32 @mbedtls_to_psa_error(i32 noundef %.0)
  br label %42

42:                                               ; preds = %20, %40, %23, %32, %16, %14, %9
  %.1 = phi i32 [ -135, %9 ], [ %15, %14 ], [ -135, %16 ], [ %41, %40 ], [ -138, %23 ], [ -135, %32 ], [ -134, %20 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %10) #3
  ret i32 %.1
}

declare i64 @mbedtls_rsa_get_len(ptr noundef) local_unnamed_addr #2

declare i32 @mbedtls_rsa_pkcs1_encrypt(ptr noundef, ptr noundef, ptr noundef, i32 noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare i32 @mbedtls_ctr_drbg_random(ptr noundef, ptr noundef, i64 noundef) #2

; Function Attrs: nounwind uwtable
declare hidden void @psa_rsa_oaep_set_padding_mode(i32 noundef, ptr noundef) local_unnamed_addr #1

declare i32 @mbedtls_rsa_rsaes_oaep_encrypt(ptr noundef, ptr noundef, ptr noundef, i32 noundef, ptr noundef, i64 noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

attributes #0 = { mustprogress 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 = { "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 = !{!"long", !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, !14, i64 0}
!12 = !{!"", !13, i64 0, !7, i64 32}
!13 = !{!"", !14, i64 0, !14, i64 2, !15, i64 4, !15, i64 8, !16, i64 12, !14, i64 24}
!14 = !{!"short", !7, i64 0}
!15 = !{!"int", !7, i64 0}
!16 = !{!"psa_key_policy_s", !15, i64 0, !15, i64 4, !15, i64 8}
!17 = !{!7, !7, i64 0}


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