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

; 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 { [32 x %struct.psa_key_slot_t], i8 }
%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
define dso_local void @psa_wipe_all_key_slots() #1 {
  %1 = alloca i16, align 2
  %2 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 2, ptr %1) #3
  store i16 1, ptr %1, align 2, !tbaa !5
  br label %3

3:                                                ; preds = %15, %0
  %4 = load i16, ptr %1, align 2, !tbaa !5
  %5 = zext i16 %4 to i32
  %6 = icmp sle i32 %5, 32
  br i1 %6, label %7, label %18

7:                                                ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  %8 = load i16, ptr %1, align 2, !tbaa !5
  %9 = zext i16 %8 to i32
  %10 = sub nsw i32 %9, 1
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [32 x %struct.psa_key_slot_t], ptr @global_data, i64 0, i64 %11
  store ptr %12, ptr %2, align 8, !tbaa !9
  %13 = load ptr, ptr %2, align 8, !tbaa !9
  %14 = call i32 @psa_wipe_key_slot(ptr noundef %13)
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  br label %15

15:                                               ; preds = %7
  %16 = load i16, ptr %1, align 2, !tbaa !5
  %17 = add i16 %16, 1
  store i16 %17, ptr %1, align 2, !tbaa !5
  br label %3, !llvm.loop !11

18:                                               ; preds = %3
  %19 = load i8, ptr getelementptr inbounds (%struct.psa_global_data_t, ptr @global_data, i32 0, i32 1), align 8
  %20 = and i8 %19, -2
  %21 = or i8 %20, 0
  store i8 %21, ptr getelementptr inbounds (%struct.psa_global_data_t, ptr @global_data, i32 0, i32 1), align 8
  call void @llvm.lifetime.end.p0(i64 2, ptr %1) #3
  ret void
}

declare i32 @psa_wipe_key_slot(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 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; 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 { [32 x %struct.psa_key_slot_t], i8 }
%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: nounwind uwtable
define dso_local void @psa_wipe_all_key_slots() local_unnamed_addr #0 {
  %1 = tail call i32 @psa_wipe_key_slot(ptr noundef nonnull @global_data) #2
  %2 = tail call i32 @psa_wipe_key_slot(ptr noundef nonnull getelementptr inbounds (i8, ptr @global_data, i64 48)) #2
  %3 = tail call i32 @psa_wipe_key_slot(ptr noundef nonnull getelementptr inbounds (i8, ptr @global_data, i64 96)) #2
  %4 = tail call i32 @psa_wipe_key_slot(ptr noundef nonnull getelementptr inbounds (i8, ptr @global_data, i64 144)) #2
  %5 = tail call i32 @psa_wipe_key_slot(ptr noundef nonnull getelementptr inbounds (i8, ptr @global_data, i64 192)) #2
  %6 = tail call i32 @psa_wipe_key_slot(ptr noundef nonnull getelementptr inbounds (i8, ptr @global_data, i64 240)) #2
  %7 = tail call i32 @psa_wipe_key_slot(ptr noundef nonnull getelementptr inbounds (i8, ptr @global_data, i64 288)) #2
  %8 = tail call i32 @psa_wipe_key_slot(ptr noundef nonnull getelementptr inbounds (i8, ptr @global_data, i64 336)) #2
  %9 = tail call i32 @psa_wipe_key_slot(ptr noundef nonnull getelementptr inbounds (i8, ptr @global_data, i64 384)) #2
  %10 = tail call i32 @psa_wipe_key_slot(ptr noundef nonnull getelementptr inbounds (i8, ptr @global_data, i64 432)) #2
  %11 = tail call i32 @psa_wipe_key_slot(ptr noundef nonnull getelementptr inbounds (i8, ptr @global_data, i64 480)) #2
  %12 = tail call i32 @psa_wipe_key_slot(ptr noundef nonnull getelementptr inbounds (i8, ptr @global_data, i64 528)) #2
  %13 = tail call i32 @psa_wipe_key_slot(ptr noundef nonnull getelementptr inbounds (i8, ptr @global_data, i64 576)) #2
  %14 = tail call i32 @psa_wipe_key_slot(ptr noundef nonnull getelementptr inbounds (i8, ptr @global_data, i64 624)) #2
  %15 = tail call i32 @psa_wipe_key_slot(ptr noundef nonnull getelementptr inbounds (i8, ptr @global_data, i64 672)) #2
  %16 = tail call i32 @psa_wipe_key_slot(ptr noundef nonnull getelementptr inbounds (i8, ptr @global_data, i64 720)) #2
  %17 = tail call i32 @psa_wipe_key_slot(ptr noundef nonnull getelementptr inbounds (i8, ptr @global_data, i64 768)) #2
  %18 = tail call i32 @psa_wipe_key_slot(ptr noundef nonnull getelementptr inbounds (i8, ptr @global_data, i64 816)) #2
  %19 = tail call i32 @psa_wipe_key_slot(ptr noundef nonnull getelementptr inbounds (i8, ptr @global_data, i64 864)) #2
  %20 = tail call i32 @psa_wipe_key_slot(ptr noundef nonnull getelementptr inbounds (i8, ptr @global_data, i64 912)) #2
  %21 = tail call i32 @psa_wipe_key_slot(ptr noundef nonnull getelementptr inbounds (i8, ptr @global_data, i64 960)) #2
  %22 = tail call i32 @psa_wipe_key_slot(ptr noundef nonnull getelementptr inbounds (i8, ptr @global_data, i64 1008)) #2
  %23 = tail call i32 @psa_wipe_key_slot(ptr noundef nonnull getelementptr inbounds (i8, ptr @global_data, i64 1056)) #2
  %24 = tail call i32 @psa_wipe_key_slot(ptr noundef nonnull getelementptr inbounds (i8, ptr @global_data, i64 1104)) #2
  %25 = tail call i32 @psa_wipe_key_slot(ptr noundef nonnull getelementptr inbounds (i8, ptr @global_data, i64 1152)) #2
  %26 = tail call i32 @psa_wipe_key_slot(ptr noundef nonnull getelementptr inbounds (i8, ptr @global_data, i64 1200)) #2
  %27 = tail call i32 @psa_wipe_key_slot(ptr noundef nonnull getelementptr inbounds (i8, ptr @global_data, i64 1248)) #2
  %28 = tail call i32 @psa_wipe_key_slot(ptr noundef nonnull getelementptr inbounds (i8, ptr @global_data, i64 1296)) #2
  %29 = tail call i32 @psa_wipe_key_slot(ptr noundef nonnull getelementptr inbounds (i8, ptr @global_data, i64 1344)) #2
  %30 = tail call i32 @psa_wipe_key_slot(ptr noundef nonnull getelementptr inbounds (i8, ptr @global_data, i64 1392)) #2
  %31 = tail call i32 @psa_wipe_key_slot(ptr noundef nonnull getelementptr inbounds (i8, ptr @global_data, i64 1440)) #2
  %32 = tail call i32 @psa_wipe_key_slot(ptr noundef nonnull getelementptr inbounds (i8, ptr @global_data, i64 1488)) #2
  %33 = load i8, ptr getelementptr inbounds (i8, ptr @global_data, i64 1536), align 8
  %34 = and i8 %33, -2
  store i8 %34, ptr getelementptr inbounds (i8, ptr @global_data, i64 1536), align 8
  ret void
}

declare i32 @psa_wipe_key_slot(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,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,SROAPass,SimplifyCFGPass,TailCallElimPass