; 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_derivation_s = type { i32, i8, i64, %union.anon.4 }
%union.anon.4 = type { %struct.psa_tls12_prf_key_derivation_s }
%struct.psa_tls12_prf_key_derivation_s = type { i8, i8, i32, ptr, i64, ptr, i64, %struct.psa_hmac_internal_data, [64 x i8], [64 x i8] }
%struct.psa_hmac_internal_data = type { %struct.psa_hash_operation_s, [128 x i8] }
%struct.psa_hash_operation_s = type { i32, %union.anon.0 }
%union.anon.0 = type { %struct.mbedtls_sha512_context }
%struct.mbedtls_sha512_context = type { [2 x i64], [8 x i64], [128 x i8], i32 }

; 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
declare dso_local i32 @psa_key_derivation_abort(ptr noundef) #1

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

20:                                               ; preds = %5
  store i32 -135, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %45

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

29:                                               ; preds = %21
  %30 = load i32, ptr %13, align 4, !tbaa !16
  store i32 %30, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %45

31:                                               ; preds = %21
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = load i16, ptr %8, align 2, !tbaa !9
  %34 = load ptr, ptr %12, align 8, !tbaa !5
  %35 = load ptr, ptr %10, align 8, !tbaa !5
  %36 = load i64, ptr %11, align 8, !tbaa !11
  %37 = call i32 @psa_key_agreement_internal(ptr noundef %32, i16 noundef zeroext %33, ptr noundef %34, ptr noundef %35, i64 noundef %36)
  store i32 %37, ptr %13, align 4, !tbaa !16
  %38 = load i32, ptr %13, align 4, !tbaa !16
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %40, label %43

40:                                               ; preds = %31
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = call i32 @psa_key_derivation_abort(ptr noundef %41)
  br label %43

43:                                               ; preds = %40, %31
  %44 = load i32, ptr %13, align 4, !tbaa !16
  store i32 %44, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %45

45:                                               ; preds = %43, %29, %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  %46 = load i32, ptr %6, align 4
  ret i32 %46
}

; Function Attrs: nounwind uwtable
declare hidden i32 @psa_key_agreement_internal(ptr noundef, i16 noundef zeroext, ptr noundef, 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 = !{!"any pointer", !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 = !{!"long", !7, i64 0}
!13 = !{!14, !15, i64 0}
!14 = !{!"psa_key_derivation_s", !15, i64 0, !15, i64 4, !12, i64 8, !7, i64 16}
!15 = !{!"int", !7, i64 0}
!16 = !{!15, !15, 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
declare dso_local i32 @psa_key_derivation_abort(ptr noundef) local_unnamed_addr #1

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

10:                                               ; preds = %5
  %11 = call i32 @psa_get_key_from_slot(i16 noundef zeroext %2, ptr noundef nonnull %6, i32 noundef 4096, i32 noundef %7)
  %.not = icmp eq i32 %11, 0
  br i1 %.not, label %12, label %17

12:                                               ; preds = %10
  %13 = load ptr, ptr %6, align 8, !tbaa !11
  %14 = call i32 @psa_key_agreement_internal(ptr noundef nonnull %0, i16 noundef zeroext %1, ptr noundef %13, ptr noundef %3, i64 noundef %4)
  %.not13 = icmp eq i32 %14, 0
  br i1 %.not13, label %17, label %15

15:                                               ; preds = %12
  %16 = call i32 @psa_key_derivation_abort(ptr noundef nonnull %0)
  br label %17

17:                                               ; preds = %12, %15, %10, %5
  %.0 = phi i32 [ -135, %5 ], [ %11, %10 ], [ %14, %15 ], [ 0, %12 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #2
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden i32 @psa_key_agreement_internal(ptr noundef, i16 noundef zeroext, ptr noundef, 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, !7, i64 0}
!6 = !{!"psa_key_derivation_s", !7, i64 0, !7, i64 4, !10, i64 8, !8, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !8, i64 0}


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