; 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: 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: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @psa_sign_hash(i16 noundef zeroext %0, i32 noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4, i64 noundef %5, ptr noundef %6) #2 {
  %8 = alloca i32, align 4
  %9 = alloca i16, align 2
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  store i16 %0, ptr %9, align 2, !tbaa !5
  store i32 %1, ptr %10, align 4, !tbaa !9
  store ptr %2, ptr %11, align 8, !tbaa !11
  store i64 %3, ptr %12, align 8, !tbaa !13
  store ptr %4, ptr %13, align 8, !tbaa !11
  store i64 %5, ptr %14, align 8, !tbaa !13
  store ptr %6, ptr %15, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #3
  %19 = load i64, ptr %14, align 8, !tbaa !13
  %20 = load ptr, ptr %15, align 8, !tbaa !11
  store i64 %19, ptr %20, align 8, !tbaa !13
  %21 = load i64, ptr %14, align 8, !tbaa !13
  %22 = icmp eq i64 %21, 0
  br i1 %22, label %23, label %24

23:                                               ; preds = %7
  store i32 -138, ptr %8, align 4
  store i32 1, ptr %18, align 4
  br label %105

24:                                               ; preds = %7
  %25 = load i16, ptr %9, align 2, !tbaa !5
  %26 = load i32, ptr %10, align 4, !tbaa !9
  %27 = call i32 @psa_get_key_from_slot(i16 noundef zeroext %25, ptr noundef %16, i32 noundef 1024, i32 noundef %26)
  store i32 %27, ptr %17, align 4, !tbaa !9
  %28 = load i32, ptr %17, align 4, !tbaa !9
  %29 = icmp ne i32 %28, 0
  br i1 %29, label %30, label %31

30:                                               ; preds = %24
  br label %88

31:                                               ; preds = %24
  %32 = load ptr, ptr %16, align 8, !tbaa !11
  %33 = getelementptr inbounds %struct.psa_key_slot_t, ptr %32, i32 0, i32 0
  %34 = getelementptr inbounds %struct.psa_core_key_attributes_t, ptr %33, i32 0, i32 0
  %35 = load i16, ptr %34, align 8, !tbaa !15
  %36 = zext i16 %35 to i32
  %37 = and i32 %36, 28672
  %38 = icmp eq i32 %37, 28672
  br i1 %38, label %40, label %39

39:                                               ; preds = %31
  store i32 -135, ptr %17, align 4, !tbaa !9
  br label %88

40:                                               ; preds = %31
  %41 = load ptr, ptr %16, align 8, !tbaa !11
  %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 !15
  %45 = zext i16 %44 to i32
  %46 = icmp eq i32 %45, 28673
  br i1 %46, label %47, label %58

47:                                               ; preds = %40
  %48 = load ptr, ptr %16, align 8, !tbaa !11
  %49 = getelementptr inbounds %struct.psa_key_slot_t, ptr %48, i32 0, i32 1
  %50 = load ptr, ptr %49, align 8, !tbaa !19
  %51 = load i32, ptr %10, align 4, !tbaa !9
  %52 = load ptr, ptr %11, align 8, !tbaa !11
  %53 = load i64, ptr %12, align 8, !tbaa !13
  %54 = load ptr, ptr %13, align 8, !tbaa !11
  %55 = load i64, ptr %14, align 8, !tbaa !13
  %56 = load ptr, ptr %15, align 8, !tbaa !11
  %57 = call i32 @psa_rsa_sign(ptr noundef %50, i32 noundef %51, ptr noundef %52, i64 noundef %53, ptr noundef %54, i64 noundef %55, ptr noundef %56)
  store i32 %57, ptr %17, align 4, !tbaa !9
  br label %87

58:                                               ; preds = %40
  %59 = load ptr, ptr %16, align 8, !tbaa !11
  %60 = getelementptr inbounds %struct.psa_key_slot_t, ptr %59, i32 0, i32 0
  %61 = getelementptr inbounds %struct.psa_core_key_attributes_t, ptr %60, i32 0, i32 0
  %62 = load i16, ptr %61, align 8, !tbaa !15
  %63 = zext i16 %62 to i32
  %64 = and i32 %63, -12289
  %65 = and i32 %64, -256
  %66 = icmp eq i32 %65, 16640
  br i1 %66, label %67, label %85

67:                                               ; preds = %58
  %68 = load i32, ptr %10, align 4, !tbaa !9
  %69 = and i32 %68, -256
  %70 = and i32 %69, -65537
  %71 = icmp eq i32 %70, 268828672
  br i1 %71, label %72, label %83

72:                                               ; preds = %67
  %73 = load ptr, ptr %16, align 8, !tbaa !11
  %74 = getelementptr inbounds %struct.psa_key_slot_t, ptr %73, i32 0, i32 1
  %75 = load ptr, ptr %74, align 8, !tbaa !19
  %76 = load i32, ptr %10, align 4, !tbaa !9
  %77 = load ptr, ptr %11, align 8, !tbaa !11
  %78 = load i64, ptr %12, align 8, !tbaa !13
  %79 = load ptr, ptr %13, align 8, !tbaa !11
  %80 = load i64, ptr %14, align 8, !tbaa !13
  %81 = load ptr, ptr %15, align 8, !tbaa !11
  %82 = call i32 @psa_ecdsa_sign(ptr noundef %75, i32 noundef %76, ptr noundef %77, i64 noundef %78, ptr noundef %79, i64 noundef %80, ptr noundef %81)
  store i32 %82, ptr %17, align 4, !tbaa !9
  br label %84

83:                                               ; preds = %67
  store i32 -135, ptr %17, align 4, !tbaa !9
  br label %84

84:                                               ; preds = %83, %72
  br label %86

85:                                               ; preds = %58
  store i32 -134, ptr %17, align 4, !tbaa !9
  br label %86

86:                                               ; preds = %85, %84
  br label %87

87:                                               ; preds = %86, %47
  br label %88

88:                                               ; preds = %87, %39, %30
  %89 = load i32, ptr %17, align 4, !tbaa !9
  %90 = icmp eq i32 %89, 0
  br i1 %90, label %91, label %100

91:                                               ; preds = %88
  %92 = load ptr, ptr %13, align 8, !tbaa !11
  %93 = load ptr, ptr %15, align 8, !tbaa !11
  %94 = load i64, ptr %93, align 8, !tbaa !13
  %95 = getelementptr inbounds i8, ptr %92, i64 %94
  %96 = load i64, ptr %14, align 8, !tbaa !13
  %97 = load ptr, ptr %15, align 8, !tbaa !11
  %98 = load i64, ptr %97, align 8, !tbaa !13
  %99 = sub i64 %96, %98
  call void @llvm.memset.p0.i64(ptr align 1 %95, i8 33, i64 %99, i1 false)
  br label %103

100:                                              ; preds = %88
  %101 = load ptr, ptr %13, align 8, !tbaa !11
  %102 = load i64, ptr %14, align 8, !tbaa !13
  call void @llvm.memset.p0.i64(ptr align 1 %101, i8 33, i64 %102, i1 false)
  br label %103

103:                                              ; preds = %100, %91
  %104 = load i32, ptr %17, align 4, !tbaa !9
  store i32 %104, ptr %8, align 4
  store i32 1, ptr %18, align 4
  br label %105

105:                                              ; preds = %103, %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  %106 = load i32, ptr %8, align 4
  ret i32 %106
}

; Function Attrs: nounwind uwtable
declare hidden i32 @psa_rsa_sign(ptr noundef, i32 noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden i32 @psa_ecdsa_sign(ptr noundef, i32 noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { 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 = { 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"

; 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: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @psa_sign_hash(i16 noundef zeroext %0, i32 noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4, i64 noundef %5, ptr noundef %6) local_unnamed_addr #2 {
  %8 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %8) #3
  store i64 %5, ptr %6, align 8, !tbaa !5
  %9 = icmp eq i64 %5, 0
  br i1 %9, label %40, label %10

10:                                               ; preds = %7
  %11 = call i32 @psa_get_key_from_slot(i16 noundef zeroext %0, ptr noundef nonnull %8, i32 noundef 1024, i32 noundef %1)
  %.not = icmp eq i32 %11, 0
  br i1 %.not, label %12, label %.thread

12:                                               ; preds = %10
  %13 = load ptr, ptr %8, align 8, !tbaa !9
  %14 = load i16, ptr %13, align 8, !tbaa !11
  %15 = zext i16 %14 to i32
  %16 = and i32 %15, 28672
  %17 = icmp eq i32 %16, 28672
  br i1 %17, label %18, label %.thread

18:                                               ; preds = %12
  %19 = icmp eq i16 %14, 28673
  br i1 %19, label %20, label %24

20:                                               ; preds = %18
  %21 = getelementptr inbounds i8, ptr %13, i64 32
  %22 = load ptr, ptr %21, align 8, !tbaa !17
  %23 = call i32 @psa_rsa_sign(ptr noundef %22, i32 noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4, i64 noundef %5, ptr noundef nonnull %6)
  br label %34

24:                                               ; preds = %18
  %25 = and i32 %15, 52992
  %26 = icmp eq i32 %25, 16640
  br i1 %26, label %27, label %.thread

27:                                               ; preds = %24
  %28 = and i32 %1, -65792
  %29 = icmp eq i32 %28, 268828672
  br i1 %29, label %30, label %.thread

30:                                               ; preds = %27
  %31 = getelementptr inbounds i8, ptr %13, i64 32
  %32 = load ptr, ptr %31, align 8, !tbaa !17
  %33 = call i32 @psa_ecdsa_sign(ptr noundef %32, i32 noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4, i64 noundef %5, ptr noundef nonnull %6)
  br label %34

34:                                               ; preds = %20, %30
  %.0 = phi i32 [ %23, %20 ], [ %33, %30 ]
  %35 = icmp eq i32 %.0, 0
  br i1 %35, label %36, label %.thread

36:                                               ; preds = %34
  %37 = load i64, ptr %6, align 8, !tbaa !5
  %38 = getelementptr inbounds i8, ptr %4, i64 %37
  %39 = sub i64 %5, %37
  call void @llvm.memset.p0.i64(ptr align 1 %38, i8 33, i64 %39, i1 false)
  br label %40

.thread:                                          ; preds = %24, %27, %12, %10, %34
  %.032 = phi i32 [ %.0, %34 ], [ -134, %24 ], [ -135, %27 ], [ -135, %12 ], [ %11, %10 ]
  call void @llvm.memset.p0.i64(ptr align 1 %4, i8 33, i64 %5, i1 false)
  br label %40

40:                                               ; preds = %36, %.thread, %7
  %.027 = phi i32 [ -138, %7 ], [ %.032, %.thread ], [ 0, %36 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %8) #3
  ret i32 %.027
}

; Function Attrs: nounwind uwtable
declare hidden i32 @psa_rsa_sign(ptr noundef, i32 noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden i32 @psa_ecdsa_sign(ptr noundef, i32 noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { 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 = { 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: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,SROAPass,SimplifyCFGPass