; LLVM IR from machinefi/psa-crypto-esp32 :: psa_layer (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_attributes_s = type { %struct.psa_core_key_attributes_t, ptr, i64 }
%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 }
%struct.psa_key_slot_t = type { %struct.psa_core_key_attributes_t, i64, %struct.key_data }
%struct.key_data = type { ptr, i64 }

; 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 @psa_allocate_buffer_to_slot(ptr noundef, i64 noundef) #1

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

; 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

declare i32 @psa_unlock_key_slot(ptr noundef) #3

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @psa_key_lifetime_is_external(i32 noundef) #4

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @psa_copy_key(i32 noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca %struct.psa_key_attributes_s, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  store i32 -151, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  store i32 -151, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  store ptr null, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  store ptr null, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 48, ptr %11) #5
  %14 = load ptr, ptr %5, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %11, ptr align 8 %14, i64 48, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  store ptr null, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  store i64 0, ptr %13, align 8, !tbaa !14
  %15 = load ptr, ptr %6, align 8, !tbaa !9
  store i32 0, ptr %15, align 4, !tbaa !5
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = call i32 @psa_get_and_lock_key_slot_with_policy(i32 noundef %16, ptr noundef %9, i32 noundef 2, i32 noundef 0)
  store i32 %17, ptr %7, align 4, !tbaa !5
  %18 = load i32, ptr %7, align 4, !tbaa !5
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %20, label %21

20:                                               ; preds = %3
  br label %135

21:                                               ; preds = %3
  %22 = load ptr, ptr %9, align 8, !tbaa !9
  %23 = load ptr, ptr %5, align 8, !tbaa !9
  %24 = call i32 @psa_validate_optional_attributes(ptr noundef %22, ptr noundef %23)
  store i32 %24, ptr %7, align 4, !tbaa !5
  %25 = load i32, ptr %7, align 4, !tbaa !5
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %28

27:                                               ; preds = %21
  br label %135

28:                                               ; preds = %21
  %29 = load ptr, ptr %9, align 8, !tbaa !9
  %30 = getelementptr inbounds %struct.psa_key_slot_t, ptr %29, i32 0, i32 0
  %31 = getelementptr inbounds %struct.psa_core_key_attributes_t, ptr %30, i32 0, i32 1
  %32 = load i16, ptr %31, align 2, !tbaa !16
  %33 = getelementptr inbounds %struct.psa_key_attributes_s, ptr %11, i32 0, i32 0
  %34 = getelementptr inbounds %struct.psa_core_key_attributes_t, ptr %33, i32 0, i32 1
  store i16 %32, ptr %34, align 2, !tbaa !21
  %35 = load ptr, ptr %9, align 8, !tbaa !9
  %36 = getelementptr inbounds %struct.psa_key_slot_t, ptr %35, i32 0, i32 0
  %37 = getelementptr inbounds %struct.psa_core_key_attributes_t, ptr %36, i32 0, i32 0
  %38 = load i16, ptr %37, align 8, !tbaa !23
  %39 = getelementptr inbounds %struct.psa_key_attributes_s, ptr %11, i32 0, i32 0
  %40 = getelementptr inbounds %struct.psa_core_key_attributes_t, ptr %39, i32 0, i32 0
  store i16 %38, ptr %40, align 8, !tbaa !24
  %41 = load ptr, ptr %9, align 8, !tbaa !9
  %42 = getelementptr inbounds %struct.psa_key_slot_t, ptr %41, i32 0, i32 0
  %43 = getelementptr inbounds %struct.psa_core_key_attributes_t, ptr %42, i32 0, i32 0
  %44 = load i16, ptr %43, align 8, !tbaa !23
  %45 = getelementptr inbounds %struct.psa_key_attributes_s, ptr %11, i32 0, i32 0
  %46 = getelementptr inbounds %struct.psa_core_key_attributes_t, ptr %45, i32 0, i32 4
  %47 = load ptr, ptr %9, align 8, !tbaa !9
  %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 4
  %50 = call i32 @psa_restrict_key_policy(i16 noundef zeroext %44, ptr noundef %46, ptr noundef %49)
  store i32 %50, ptr %7, align 4, !tbaa !5
  %51 = load i32, ptr %7, align 4, !tbaa !5
  %52 = icmp ne i32 %51, 0
  br i1 %52, label %53, label %54

53:                                               ; preds = %28
  br label %135

54:                                               ; preds = %28
  %55 = call i32 @psa_start_key_creation(i32 noundef 3, ptr noundef %11, ptr noundef %10, ptr noundef %12)
  store i32 %55, ptr %7, align 4, !tbaa !5
  %56 = load i32, ptr %7, align 4, !tbaa !5
  %57 = icmp ne i32 %56, 0
  br i1 %57, label %58, label %59

58:                                               ; preds = %54
  br label %135

59:                                               ; preds = %54
  %60 = load ptr, ptr %10, align 8, !tbaa !9
  %61 = getelementptr inbounds %struct.psa_key_slot_t, ptr %60, i32 0, i32 0
  %62 = getelementptr inbounds %struct.psa_core_key_attributes_t, ptr %61, i32 0, i32 2
  %63 = load i32, ptr %62, align 4, !tbaa !25
  %64 = lshr i32 %63, 8
  %65 = load ptr, ptr %9, align 8, !tbaa !9
  %66 = getelementptr inbounds %struct.psa_key_slot_t, ptr %65, i32 0, i32 0
  %67 = getelementptr inbounds %struct.psa_core_key_attributes_t, ptr %66, i32 0, i32 2
  %68 = load i32, ptr %67, align 4, !tbaa !25
  %69 = lshr i32 %68, 8
  %70 = icmp ne i32 %64, %69
  br i1 %70, label %71, label %72

71:                                               ; preds = %59
  store i32 -134, ptr %7, align 4, !tbaa !5
  br label %135

72:                                               ; preds = %59
  %73 = getelementptr inbounds %struct.psa_key_attributes_s, ptr %11, i32 0, i32 0
  %74 = getelementptr inbounds %struct.psa_core_key_attributes_t, ptr %73, i32 0, i32 2
  %75 = load i32, ptr %74, align 4, !tbaa !26
  %76 = call i32 @psa_key_lifetime_is_external(i32 noundef %75)
  %77 = icmp ne i32 %76, 0
  br i1 %77, label %78, label %115

78:                                               ; preds = %72
  %79 = call i32 @psa_driver_wrapper_get_key_buffer_size(ptr noundef %11, ptr noundef %13)
  store i32 %79, ptr %7, align 4, !tbaa !5
  %80 = load i32, ptr %7, align 4, !tbaa !5
  %81 = icmp ne i32 %80, 0
  br i1 %81, label %82, label %83

82:                                               ; preds = %78
  br label %135

83:                                               ; preds = %78
  %84 = load ptr, ptr %10, align 8, !tbaa !9
  %85 = load i64, ptr %13, align 8, !tbaa !14
  %86 = call i32 @psa_allocate_buffer_to_slot(ptr noundef %84, i64 noundef %85)
  store i32 %86, ptr %7, align 4, !tbaa !5
  %87 = load i32, ptr %7, align 4, !tbaa !5
  %88 = icmp ne i32 %87, 0
  br i1 %88, label %89, label %90

89:                                               ; preds = %83
  br label %135

90:                                               ; preds = %83
  %91 = load ptr, ptr %9, align 8, !tbaa !9
  %92 = getelementptr inbounds %struct.psa_key_slot_t, ptr %91, i32 0, i32 2
  %93 = getelementptr inbounds %struct.key_data, ptr %92, i32 0, i32 0
  %94 = load ptr, ptr %93, align 8, !tbaa !27
  %95 = load ptr, ptr %9, align 8, !tbaa !9
  %96 = getelementptr inbounds %struct.psa_key_slot_t, ptr %95, i32 0, i32 2
  %97 = getelementptr inbounds %struct.key_data, ptr %96, i32 0, i32 1
  %98 = load i64, ptr %97, align 8, !tbaa !28
  %99 = load ptr, ptr %10, align 8, !tbaa !9
  %100 = getelementptr inbounds %struct.psa_key_slot_t, ptr %99, i32 0, i32 2
  %101 = getelementptr inbounds %struct.key_data, ptr %100, i32 0, i32 0
  %102 = load ptr, ptr %101, align 8, !tbaa !27
  %103 = load ptr, ptr %10, align 8, !tbaa !9
  %104 = getelementptr inbounds %struct.psa_key_slot_t, ptr %103, i32 0, i32 2
  %105 = getelementptr inbounds %struct.key_data, ptr %104, i32 0, i32 1
  %106 = load i64, ptr %105, align 8, !tbaa !28
  %107 = load ptr, ptr %10, align 8, !tbaa !9
  %108 = getelementptr inbounds %struct.psa_key_slot_t, ptr %107, i32 0, i32 2
  %109 = getelementptr inbounds %struct.key_data, ptr %108, i32 0, i32 1
  %110 = call i32 @psa_driver_wrapper_copy_key(ptr noundef %11, ptr noundef %94, i64 noundef %98, ptr noundef %102, i64 noundef %106, ptr noundef %109)
  store i32 %110, ptr %7, align 4, !tbaa !5
  %111 = load i32, ptr %7, align 4, !tbaa !5
  %112 = icmp ne i32 %111, 0
  br i1 %112, label %113, label %114

113:                                              ; preds = %90
  br label %135

114:                                              ; preds = %90
  br label %130

115:                                              ; preds = %72
  %116 = load ptr, ptr %10, align 8, !tbaa !9
  %117 = load ptr, ptr %9, align 8, !tbaa !9
  %118 = getelementptr inbounds %struct.psa_key_slot_t, ptr %117, i32 0, i32 2
  %119 = getelementptr inbounds %struct.key_data, ptr %118, i32 0, i32 0
  %120 = load ptr, ptr %119, align 8, !tbaa !27
  %121 = load ptr, ptr %9, align 8, !tbaa !9
  %122 = getelementptr inbounds %struct.psa_key_slot_t, ptr %121, i32 0, i32 2
  %123 = getelementptr inbounds %struct.key_data, ptr %122, i32 0, i32 1
  %124 = load i64, ptr %123, align 8, !tbaa !28
  %125 = call i32 @psa_copy_key_material_into_slot(ptr noundef %116, ptr noundef %120, i64 noundef %124)
  store i32 %125, ptr %7, align 4, !tbaa !5
  %126 = load i32, ptr %7, align 4, !tbaa !5
  %127 = icmp ne i32 %126, 0
  br i1 %127, label %128, label %129

128:                                              ; preds = %115
  br label %135

129:                                              ; preds = %115
  br label %130

130:                                              ; preds = %129, %114
  %131 = load ptr, ptr %10, align 8, !tbaa !9
  %132 = load ptr, ptr %12, align 8, !tbaa !9
  %133 = load ptr, ptr %6, align 8, !tbaa !9
  %134 = call i32 @psa_finish_key_creation(ptr noundef %131, ptr noundef %132, ptr noundef %133)
  store i32 %134, ptr %7, align 4, !tbaa !5
  br label %135

135:                                              ; preds = %130, %128, %113, %89, %82, %71, %58, %53, %27, %20
  %136 = load i32, ptr %7, align 4, !tbaa !5
  %137 = icmp ne i32 %136, 0
  br i1 %137, label %138, label %141

138:                                              ; preds = %135
  %139 = load ptr, ptr %10, align 8, !tbaa !9
  %140 = load ptr, ptr %12, align 8, !tbaa !9
  call void @psa_fail_key_creation(ptr noundef %139, ptr noundef %140)
  br label %141

141:                                              ; preds = %138, %135
  %142 = load ptr, ptr %9, align 8, !tbaa !9
  %143 = call i32 @psa_unlock_key_slot(ptr noundef %142)
  store i32 %143, ptr %8, align 4, !tbaa !5
  %144 = load i32, ptr %7, align 4, !tbaa !5
  %145 = icmp eq i32 %144, 0
  br i1 %145, label %146, label %148

146:                                              ; preds = %141
  %147 = load i32, ptr %8, align 4, !tbaa !5
  br label %150

148:                                              ; preds = %141
  %149 = load i32, ptr %7, align 4, !tbaa !5
  br label %150

150:                                              ; preds = %148, %146
  %151 = phi i32 [ %147, %146 ], [ %149, %148 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 48, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  ret i32 %151
}

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

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

declare i32 @psa_driver_wrapper_copy_key(ptr noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef) #3

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #5 = { 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 = !{i64 0, i64 2, !12, i64 2, i64 2, !12, i64 4, i64 4, !5, i64 8, i64 4, !5, i64 12, i64 4, !5, i64 16, i64 4, !5, i64 20, i64 4, !5, i64 24, i64 2, !12, i64 32, i64 8, !9, i64 40, i64 8, !14}
!12 = !{!13, !13, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!17, !13, i64 2}
!17 = !{!"", !18, i64 0, !15, i64 32, !20, i64 40}
!18 = !{!"", !13, i64 0, !13, i64 2, !6, i64 4, !6, i64 8, !19, i64 12, !13, i64 24}
!19 = !{!"psa_key_policy_s", !6, i64 0, !6, i64 4, !6, i64 8}
!20 = !{!"key_data", !10, i64 0, !15, i64 8}
!21 = !{!22, !13, i64 2}
!22 = !{!"psa_key_attributes_s", !18, i64 0, !10, i64 32, !15, i64 40}
!23 = !{!17, !13, i64 0}
!24 = !{!22, !13, i64 0}
!25 = !{!17, !6, i64 4}
!26 = !{!22, !6, i64 4}
!27 = !{!17, !10, i64 40}
!28 = !{!17, !15, i64 48}


; 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_key_attributes_s = type { %struct.psa_core_key_attributes_t, ptr, i64 }
%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 }

; 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 dso_local i32 @psa_allocate_buffer_to_slot(ptr noundef, i64 noundef) local_unnamed_addr #1

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

; 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) #2

declare i32 @psa_unlock_key_slot(ptr noundef) local_unnamed_addr #3

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @psa_key_lifetime_is_external(i32 noundef) local_unnamed_addr #4

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @psa_copy_key(i32 noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca %struct.psa_key_attributes_s, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #5
  store ptr null, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #5
  store ptr null, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 48, ptr nonnull %6) #5
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(48) %6, ptr noundef nonnull align 8 dereferenceable(48) %1, i64 48, i1 false), !tbaa.struct !9
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #5
  store ptr null, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %8) #5
  store i64 0, ptr %8, align 8, !tbaa !14
  store i32 0, ptr %2, align 4, !tbaa !12
  %9 = call i32 @psa_get_and_lock_key_slot_with_policy(i32 noundef %0, ptr noundef nonnull %4, i32 noundef 2, i32 noundef 0)
  %.not = icmp eq i32 %9, 0
  br i1 %.not, label %10, label %63

10:                                               ; preds = %3
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = call i32 @psa_validate_optional_attributes(ptr noundef %11, ptr noundef nonnull %1)
  %.not24 = icmp eq i32 %12, 0
  br i1 %.not24, label %13, label %63

13:                                               ; preds = %10
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = load <2 x i16>, ptr %14, align 8, !tbaa !10
  store <2 x i16> %15, ptr %6, align 8, !tbaa !10
  %16 = getelementptr inbounds i8, ptr %6, i64 12
  %17 = getelementptr inbounds i8, ptr %14, i64 12
  %18 = extractelement <2 x i16> %15, i64 0
  %19 = call i32 @psa_restrict_key_policy(i16 noundef zeroext %18, ptr noundef nonnull %16, ptr noundef nonnull %17)
  %.not25 = icmp eq i32 %19, 0
  br i1 %.not25, label %20, label %63

20:                                               ; preds = %13
  %21 = call i32 @psa_start_key_creation(i32 noundef 3, ptr noundef nonnull %6, ptr noundef nonnull %5, ptr noundef nonnull %7)
  %.not26 = icmp eq i32 %21, 0
  br i1 %.not26, label %22, label %63

22:                                               ; preds = %20
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %23, i64 4
  %25 = load i32, ptr %24, align 4, !tbaa !16
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %26, i64 4
  %28 = load i32, ptr %27, align 4, !tbaa !16
  %.not27.unshifted = xor i32 %28, %25
  %.not27 = icmp ult i32 %.not27.unshifted, 256
  br i1 %.not27, label %29, label %63

29:                                               ; preds = %22
  %30 = getelementptr inbounds i8, ptr %6, i64 4
  %31 = load i32, ptr %30, align 4, !tbaa !21
  %32 = call i32 @psa_key_lifetime_is_external(i32 noundef %31)
  %.not28 = icmp eq i32 %32, 0
  br i1 %.not28, label %51, label %33

33:                                               ; preds = %29
  %34 = call i32 @psa_driver_wrapper_get_key_buffer_size(ptr noundef nonnull %6, ptr noundef nonnull %8) #5
  %.not30 = icmp eq i32 %34, 0
  br i1 %.not30, label %35, label %63

35:                                               ; preds = %33
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = load i64, ptr %8, align 8, !tbaa !14
  %38 = call i32 @psa_allocate_buffer_to_slot(ptr noundef %36, i64 noundef %37)
  %.not31 = icmp eq i32 %38, 0
  br i1 %.not31, label %39, label %63

39:                                               ; preds = %35
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds i8, ptr %40, i64 40
  %42 = load ptr, ptr %41, align 8, !tbaa !23
  %43 = getelementptr inbounds i8, ptr %40, i64 48
  %44 = load i64, ptr %43, align 8, !tbaa !24
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds i8, ptr %45, i64 40
  %47 = load ptr, ptr %46, align 8, !tbaa !23
  %48 = getelementptr inbounds i8, ptr %45, i64 48
  %49 = load i64, ptr %48, align 8, !tbaa !24
  %50 = call i32 @psa_driver_wrapper_copy_key(ptr noundef nonnull %6, ptr noundef %42, i64 noundef %44, ptr noundef %47, i64 noundef %49, ptr noundef nonnull %48) #5
  %.not32 = icmp eq i32 %50, 0
  br i1 %.not32, label %59, label %63

51:                                               ; preds = %29
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds i8, ptr %53, i64 40
  %55 = load ptr, ptr %54, align 8, !tbaa !23
  %56 = getelementptr inbounds i8, ptr %53, i64 48
  %57 = load i64, ptr %56, align 8, !tbaa !24
  %58 = call i32 @psa_copy_key_material_into_slot(ptr noundef %52, ptr noundef %55, i64 noundef %57)
  %.not29 = icmp eq i32 %58, 0
  br i1 %.not29, label %59, label %63

59:                                               ; preds = %39, %51
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  %62 = call i32 @psa_finish_key_creation(ptr noundef %60, ptr noundef %61, ptr noundef nonnull %2)
  %.not33 = icmp eq i32 %62, 0
  br i1 %.not33, label %68, label %63

63:                                               ; preds = %59, %3, %10, %13, %20, %33, %35, %39, %51, %22
  %.036 = phi i32 [ %62, %59 ], [ -134, %22 ], [ %58, %51 ], [ %50, %39 ], [ %38, %35 ], [ %34, %33 ], [ %21, %20 ], [ %19, %13 ], [ %12, %10 ], [ %9, %3 ]
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  call void @psa_fail_key_creation(ptr noundef %64, ptr noundef %65)
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = call i32 @psa_unlock_key_slot(ptr noundef %66) #5
  br label %71

68:                                               ; preds = %59
  %69 = load ptr, ptr %4, align 8, !tbaa !5
  %70 = call i32 @psa_unlock_key_slot(ptr noundef %69) #5
  br label %71

71:                                               ; preds = %63, %68
  %72 = phi i32 [ %70, %68 ], [ %.036, %63 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #5
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #5
  ret i32 %72
}

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

declare i32 @psa_driver_wrapper_get_key_buffer_size(ptr noundef, ptr noundef) local_unnamed_addr #3

declare i32 @psa_driver_wrapper_copy_key(ptr noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #3

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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #5 = { 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 = !{i64 0, i64 2, !10, i64 2, i64 2, !10, i64 4, i64 4, !12, i64 8, i64 4, !12, i64 12, i64 4, !12, i64 16, i64 4, !12, i64 20, i64 4, !12, i64 24, i64 2, !10, i64 32, i64 8, !5, i64 40, i64 8, !14}
!10 = !{!11, !11, i64 0}
!11 = !{!"short", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!17, !13, i64 4}
!17 = !{!"", !18, i64 0, !15, i64 32, !20, i64 40}
!18 = !{!"", !11, i64 0, !11, i64 2, !13, i64 4, !13, i64 8, !19, i64 12, !11, i64 24}
!19 = !{!"psa_key_policy_s", !13, i64 0, !13, i64 4, !13, i64 8}
!20 = !{!"key_data", !6, i64 0, !15, i64 8}
!21 = !{!22, !13, i64 4}
!22 = !{!"psa_key_attributes_s", !18, i64 0, !6, i64 32, !15, i64 40}
!23 = !{!17, !6, i64 40}
!24 = !{!17, !15, i64 48}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass