; 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_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 }

; Function Attrs: nounwind uwtable
define dso_local i32 @psa_import_key_into_slot(ptr noundef %0, ptr noundef %1, i64 noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !11
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.psa_key_slot_t, ptr %11, i32 0, i32 0
  %13 = getelementptr inbounds %struct.psa_core_key_attributes_t, ptr %12, i32 0, i32 0
  %14 = load i16, ptr %13, align 8, !tbaa !13
  %15 = call i32 @key_type_is_raw_bytes(i16 noundef zeroext %14)
  %16 = icmp ne i32 %15, 0
  br i1 %16, label %17, label %54

17:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %18 = load i64, ptr %7, align 8, !tbaa !9
  %19 = mul i64 %18, 8
  store i64 %19, ptr %9, align 8, !tbaa !9
  %20 = load i64, ptr %7, align 8, !tbaa !9
  %21 = icmp ugt i64 %20, 2305843009213693951
  br i1 %21, label %22, label %23

22:                                               ; preds = %17
  store i32 -134, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %51

23:                                               ; preds = %17
  %24 = load i64, ptr %9, align 8, !tbaa !9
  %25 = icmp ugt i64 %24, 65528
  br i1 %25, label %26, label %27

26:                                               ; preds = %23
  store i32 -134, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %51

27:                                               ; preds = %23
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.psa_key_slot_t, ptr %28, i32 0, i32 0
  %30 = getelementptr inbounds %struct.psa_core_key_attributes_t, ptr %29, i32 0, i32 0
  %31 = load i16, ptr %30, align 8, !tbaa !13
  %32 = load i64, ptr %9, align 8, !tbaa !9
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.psa_key_slot_t, ptr %33, i32 0, i32 1
  %35 = call i32 @prepare_raw_data_slot(i16 noundef zeroext %31, i64 noundef %32, ptr noundef %34)
  store i32 %35, ptr %8, align 4, !tbaa !11
  %36 = load i32, ptr %8, align 4, !tbaa !11
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %38, label %40

38:                                               ; preds = %27
  %39 = load i32, ptr %8, align 4, !tbaa !11
  store i32 %39, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %51

40:                                               ; preds = %27
  %41 = load i64, ptr %7, align 8, !tbaa !9
  %42 = icmp ne i64 %41, 0
  br i1 %42, label %43, label %50

43:                                               ; preds = %40
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.psa_key_slot_t, ptr %44, i32 0, i32 1
  %46 = getelementptr inbounds %struct.raw_data, ptr %45, i32 0, i32 0
  %47 = load ptr, ptr %46, align 8, !tbaa !18
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = load i64, ptr %7, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %47, ptr align 1 %48, i64 %49, i1 false)
  br label %50

50:                                               ; preds = %43, %40
  store i32 0, ptr %10, align 4
  br label %51

51:                                               ; preds = %50, %38, %26, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  %52 = load i32, ptr %10, align 4
  switch i32 %52, label %153 [
    i32 0, label %53
  ]

53:                                               ; preds = %51
  br label %142

54:                                               ; preds = %3
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %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 !13
  %59 = zext i16 %58 to i32
  %60 = and i32 %59, -256
  %61 = icmp eq i32 %60, 28928
  br i1 %61, label %62, label %87

62:                                               ; preds = %54
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.psa_key_slot_t, ptr %63, i32 0, i32 0
  %65 = getelementptr inbounds %struct.psa_core_key_attributes_t, ptr %64, i32 0, i32 0
  %66 = load i16, ptr %65, align 8, !tbaa !13
  %67 = zext i16 %66 to i32
  %68 = and i32 %67, -12289
  %69 = and i32 %68, -256
  %70 = icmp eq i32 %69, 16640
  br i1 %70, label %71, label %78

71:                                               ; preds = %62
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.psa_key_slot_t, ptr %72, i32 0, i32 0
  %74 = getelementptr inbounds %struct.psa_core_key_attributes_t, ptr %73, i32 0, i32 0
  %75 = load i16, ptr %74, align 8, !tbaa !13
  %76 = zext i16 %75 to i32
  %77 = and i32 %76, 255
  br label %79

78:                                               ; preds = %62
  br label %79

79:                                               ; preds = %78, %71
  %80 = phi i32 [ %77, %71 ], [ 0, %78 ]
  %81 = trunc i32 %80 to i8
  %82 = load ptr, ptr %6, align 8, !tbaa !5
  %83 = load i64, ptr %7, align 8, !tbaa !9
  %84 = load ptr, ptr %5, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.psa_key_slot_t, ptr %84, i32 0, i32 1
  %86 = call i32 @psa_import_ec_private_key(i8 noundef zeroext %81, ptr noundef %82, i64 noundef %83, ptr noundef %85)
  store i32 %86, ptr %8, align 4, !tbaa !11
  br label %141

87:                                               ; preds = %54
  %88 = load ptr, ptr %5, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.psa_key_slot_t, ptr %88, i32 0, i32 0
  %90 = getelementptr inbounds %struct.psa_core_key_attributes_t, ptr %89, i32 0, i32 0
  %91 = load i16, ptr %90, align 8, !tbaa !13
  %92 = zext i16 %91 to i32
  %93 = and i32 %92, -256
  %94 = icmp eq i32 %93, 16640
  br i1 %94, label %95, label %120

95:                                               ; preds = %87
  %96 = load ptr, ptr %5, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.psa_key_slot_t, ptr %96, i32 0, i32 0
  %98 = getelementptr inbounds %struct.psa_core_key_attributes_t, ptr %97, i32 0, i32 0
  %99 = load i16, ptr %98, align 8, !tbaa !13
  %100 = zext i16 %99 to i32
  %101 = and i32 %100, -12289
  %102 = and i32 %101, -256
  %103 = icmp eq i32 %102, 16640
  br i1 %103, label %104, label %111

104:                                              ; preds = %95
  %105 = load ptr, ptr %5, align 8, !tbaa !5
  %106 = getelementptr inbounds %struct.psa_key_slot_t, ptr %105, i32 0, i32 0
  %107 = getelementptr inbounds %struct.psa_core_key_attributes_t, ptr %106, i32 0, i32 0
  %108 = load i16, ptr %107, align 8, !tbaa !13
  %109 = zext i16 %108 to i32
  %110 = and i32 %109, 255
  br label %112

111:                                              ; preds = %95
  br label %112

112:                                              ; preds = %111, %104
  %113 = phi i32 [ %110, %104 ], [ 0, %111 ]
  %114 = trunc i32 %113 to i8
  %115 = load ptr, ptr %6, align 8, !tbaa !5
  %116 = load i64, ptr %7, align 8, !tbaa !9
  %117 = load ptr, ptr %5, align 8, !tbaa !5
  %118 = getelementptr inbounds %struct.psa_key_slot_t, ptr %117, i32 0, i32 1
  %119 = call i32 @psa_import_ec_public_key(i8 noundef zeroext %114, ptr noundef %115, i64 noundef %116, ptr noundef %118)
  store i32 %119, ptr %8, align 4, !tbaa !11
  br label %140

120:                                              ; preds = %87
  %121 = load ptr, ptr %5, align 8, !tbaa !5
  %122 = getelementptr inbounds %struct.psa_key_slot_t, ptr %121, i32 0, i32 0
  %123 = getelementptr inbounds %struct.psa_core_key_attributes_t, ptr %122, i32 0, i32 0
  %124 = load i16, ptr %123, align 8, !tbaa !13
  %125 = zext i16 %124 to i32
  %126 = and i32 %125, -12289
  %127 = icmp eq i32 %126, 16385
  br i1 %127, label %128, label %138

128:                                              ; preds = %120
  %129 = load ptr, ptr %5, align 8, !tbaa !5
  %130 = getelementptr inbounds %struct.psa_key_slot_t, ptr %129, i32 0, i32 0
  %131 = getelementptr inbounds %struct.psa_core_key_attributes_t, ptr %130, i32 0, i32 0
  %132 = load i16, ptr %131, align 8, !tbaa !13
  %133 = load ptr, ptr %6, align 8, !tbaa !5
  %134 = load i64, ptr %7, align 8, !tbaa !9
  %135 = load ptr, ptr %5, align 8, !tbaa !5
  %136 = getelementptr inbounds %struct.psa_key_slot_t, ptr %135, i32 0, i32 1
  %137 = call i32 @psa_import_rsa_key(i16 noundef zeroext %132, ptr noundef %133, i64 noundef %134, ptr noundef %136)
  store i32 %137, ptr %8, align 4, !tbaa !11
  br label %139

138:                                              ; preds = %120
  store i32 -134, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %153

139:                                              ; preds = %128
  br label %140

140:                                              ; preds = %139, %112
  br label %141

141:                                              ; preds = %140, %79
  br label %142

142:                                              ; preds = %141, %53
  %143 = load i32, ptr %8, align 4, !tbaa !11
  %144 = icmp eq i32 %143, 0
  br i1 %144, label %145, label %151

145:                                              ; preds = %142
  %146 = load ptr, ptr %5, align 8, !tbaa !5
  %147 = call zeroext i16 @psa_calculate_key_bits(ptr noundef %146)
  %148 = load ptr, ptr %5, align 8, !tbaa !5
  %149 = getelementptr inbounds %struct.psa_key_slot_t, ptr %148, i32 0, i32 0
  %150 = getelementptr inbounds %struct.psa_core_key_attributes_t, ptr %149, i32 0, i32 1
  store i16 %147, ptr %150, align 2, !tbaa !19
  br label %151

151:                                              ; preds = %145, %142
  %152 = load i32, ptr %8, align 4, !tbaa !11
  store i32 %152, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %153

153:                                              ; preds = %151, %138, %51
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %154 = load i32, ptr %4, align 4
  ret i32 %154
}

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

; Function Attrs: nounwind uwtable
declare hidden i32 @key_type_is_raw_bytes(i16 noundef zeroext) #0

; Function Attrs: nounwind uwtable
declare hidden i32 @prepare_raw_data_slot(i16 noundef zeroext, i64 noundef, ptr noundef) #0

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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

; Function Attrs: nounwind uwtable
declare hidden i32 @psa_import_ec_private_key(i8 noundef zeroext, ptr noundef, i64 noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden i32 @psa_import_ec_public_key(i8 noundef zeroext, ptr noundef, i64 noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden i32 @psa_import_rsa_key(i16 noundef zeroext, ptr noundef, i64 noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden zeroext i16 @psa_calculate_key_bits(ptr noundef) #0

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !16, i64 0}
!14 = !{!"", !15, i64 0, !7, i64 32}
!15 = !{!"", !16, i64 0, !16, i64 2, !12, i64 4, !12, i64 8, !17, i64 12, !16, i64 24}
!16 = !{!"short", !7, i64 0}
!17 = !{!"psa_key_policy_s", !12, i64 0, !12, i64 4, !12, i64 8}
!18 = !{!7, !7, i64 0}
!19 = !{!14, !16, i64 2}


; 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
define dso_local i32 @psa_import_key_into_slot(ptr noundef %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = load i16, ptr %0, align 8, !tbaa !5
  %5 = tail call i32 @key_type_is_raw_bytes(i16 noundef zeroext %4)
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %17, label %6

6:                                                ; preds = %3
  %7 = shl i64 %2, 3
  %8 = icmp ugt i64 %2, 2305843009213693951
  %9 = icmp ugt i64 %7, 65528
  %or.cond = or i1 %8, %9
  br i1 %or.cond, label %37, label %10

10:                                               ; preds = %6
  %11 = load i16, ptr %0, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %0, i64 32
  %13 = tail call i32 @prepare_raw_data_slot(i16 noundef zeroext %11, i64 noundef %7, ptr noundef nonnull %12)
  %.not43 = icmp eq i32 %13, 0
  br i1 %.not43, label %14, label %37

14:                                               ; preds = %10
  %.not44 = icmp eq i64 %2, 0
  br i1 %.not44, label %.thread48, label %15

15:                                               ; preds = %14
  %16 = load ptr, ptr %12, align 8, !tbaa !13
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %16, ptr align 1 %1, i64 %2, i1 false)
  br label %.thread48

17:                                               ; preds = %3
  %18 = load i16, ptr %0, align 8, !tbaa !5
  %trunc = and i16 %18, -256
  switch i16 %trunc, label %27 [
    i16 28928, label %19
    i16 16640, label %23
  ]

19:                                               ; preds = %17
  %20 = trunc i16 %18 to i8
  %21 = getelementptr inbounds i8, ptr %0, i64 32
  %22 = tail call i32 @psa_import_ec_private_key(i8 noundef zeroext %20, ptr noundef %1, i64 noundef %2, ptr noundef nonnull %21)
  br label %33

23:                                               ; preds = %17
  %24 = trunc i16 %18 to i8
  %25 = getelementptr inbounds i8, ptr %0, i64 32
  %26 = tail call i32 @psa_import_ec_public_key(i8 noundef zeroext %24, ptr noundef %1, i64 noundef %2, ptr noundef nonnull %25)
  br label %33

27:                                               ; preds = %17
  %28 = and i16 %18, -12289
  %29 = icmp eq i16 %28, 16385
  br i1 %29, label %30, label %37

30:                                               ; preds = %27
  %31 = getelementptr inbounds i8, ptr %0, i64 32
  %32 = tail call i32 @psa_import_rsa_key(i16 noundef zeroext %18, ptr noundef %1, i64 noundef %2, ptr noundef nonnull %31)
  br label %33

33:                                               ; preds = %19, %30, %23
  %.137 = phi i32 [ %22, %19 ], [ %26, %23 ], [ %32, %30 ]
  %34 = icmp eq i32 %.137, 0
  br i1 %34, label %.thread48, label %37

.thread48:                                        ; preds = %15, %14, %33
  %35 = tail call zeroext i16 @psa_calculate_key_bits(ptr noundef nonnull %0)
  %36 = getelementptr inbounds i8, ptr %0, i64 2
  store i16 %35, ptr %36, align 2, !tbaa !14
  br label %37

37:                                               ; preds = %6, %10, %33, %.thread48, %27
  %.1 = phi i32 [ -134, %27 ], [ 0, %.thread48 ], [ %.137, %33 ], [ -134, %6 ], [ %13, %10 ]
  ret i32 %.1
}

; Function Attrs: nounwind uwtable
declare hidden i32 @key_type_is_raw_bytes(i16 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i32 @prepare_raw_data_slot(i16 noundef zeroext, i64 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: nounwind uwtable
declare hidden i32 @psa_import_ec_private_key(i8 noundef zeroext, ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i32 @psa_import_ec_public_key(i8 noundef zeroext, ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i32 @psa_import_rsa_key(i16 noundef zeroext, ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden zeroext i16 @psa_calculate_key_bits(ptr noundef) local_unnamed_addr #0

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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }

!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, !8, i64 0}
!6 = !{!"", !7, i64 0, !9, i64 32}
!7 = !{!"", !8, i64 0, !8, i64 2, !11, i64 4, !11, i64 8, !12, i64 12, !8, i64 24}
!8 = !{!"short", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!"psa_key_policy_s", !11, i64 0, !11, i64 4, !11, i64 8}
!13 = !{!9, !9, i64 0}
!14 = !{!6, !8, i64 2}


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