; 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"

; 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
define dso_local i32 @psa_raw_key_agreement(i32 noundef %0, i16 noundef zeroext %1, ptr noundef %2, i64 noundef %3, ptr noundef %4, i64 noundef %5, ptr noundef %6) #1 {
  %8 = alloca i32, align 4
  %9 = alloca i16, align 2
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca i32, align 4
  store i32 %0, ptr %8, align 4, !tbaa !5
  store i16 %1, ptr %9, align 2, !tbaa !9
  store ptr %2, ptr %10, align 8, !tbaa !11
  store i64 %3, ptr %11, align 8, !tbaa !13
  store ptr %4, ptr %12, align 8, !tbaa !11
  store i64 %5, ptr %13, align 8, !tbaa !13
  store ptr %6, ptr %14, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #2
  %17 = load i32, ptr %8, align 4, !tbaa !5
  %18 = and i32 %17, 2130706432
  %19 = icmp eq i32 %18, 805306368
  br i1 %19, label %21, label %20

20:                                               ; preds = %7
  store i32 -135, ptr %16, align 4, !tbaa !5
  br label %37

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

27:                                               ; preds = %21
  br label %37

28:                                               ; preds = %21
  %29 = load i32, ptr %8, align 4, !tbaa !5
  %30 = load ptr, ptr %15, align 8, !tbaa !11
  %31 = load ptr, ptr %10, align 8, !tbaa !11
  %32 = load i64, ptr %11, align 8, !tbaa !13
  %33 = load ptr, ptr %12, align 8, !tbaa !11
  %34 = load i64, ptr %13, align 8, !tbaa !13
  %35 = load ptr, ptr %14, align 8, !tbaa !11
  %36 = call i32 @psa_key_agreement_raw_internal(i32 noundef %29, ptr noundef %30, ptr noundef %31, i64 noundef %32, ptr noundef %33, i64 noundef %34, ptr noundef %35)
  store i32 %36, ptr %16, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %28, %27, %20
  %38 = load i32, ptr %16, align 4, !tbaa !5
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %40, label %46

40:                                               ; preds = %37
  %41 = load ptr, ptr %12, align 8, !tbaa !11
  %42 = load i64, ptr %13, align 8, !tbaa !13
  %43 = call i32 @psa_generate_random(ptr noundef %41, i64 noundef %42)
  %44 = load i64, ptr %13, align 8, !tbaa !13
  %45 = load ptr, ptr %14, align 8, !tbaa !11
  store i64 %44, ptr %45, align 8, !tbaa !13
  br label %46

46:                                               ; preds = %40, %37
  %47 = load i32, ptr %16, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #2
  ret i32 %47
}

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

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

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 = { 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 = !{!"short", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !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: 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
define dso_local i32 @psa_raw_key_agreement(i32 noundef %0, i16 noundef zeroext %1, ptr noundef %2, i64 noundef %3, ptr noundef %4, i64 noundef %5, ptr noundef %6) local_unnamed_addr #1 {
  %8 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %8) #2
  %9 = and i32 %0, 2130706432
  %10 = icmp eq i32 %9, 805306368
  br i1 %10, label %11, label %.thread

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

13:                                               ; preds = %11
  %14 = load ptr, ptr %8, align 8, !tbaa !5
  %15 = call i32 @psa_key_agreement_raw_internal(i32 noundef %0, ptr noundef %14, ptr noundef %2, i64 noundef %3, ptr noundef %4, i64 noundef %5, ptr noundef %6)
  %.not16 = icmp eq i32 %15, 0
  br i1 %.not16, label %17, label %.thread

.thread:                                          ; preds = %7, %11, %13
  %.019 = phi i32 [ %15, %13 ], [ -135, %7 ], [ %12, %11 ]
  %16 = call i32 @psa_generate_random(ptr noundef %4, i64 noundef %5)
  store i64 %5, ptr %6, align 8, !tbaa !9
  br label %17

17:                                               ; preds = %.thread, %13
  %.020 = phi i32 [ %.019, %.thread ], [ 0, %13 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %8) #2
  ret i32 %.020
}

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

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

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 = { 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}


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