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

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

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

19:                                               ; preds = %3
  store i32 -137, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %91

20:                                               ; preds = %3
  %21 = load i64, ptr %7, align 8, !tbaa !9
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.psa_key_derivation_s, ptr %22, i32 0, i32 2
  %24 = load i64, ptr %23, align 8, !tbaa !15
  %25 = icmp ugt i64 %21, %24
  br i1 %25, label %26, label %29

26:                                               ; preds = %20
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.psa_key_derivation_s, ptr %27, i32 0, i32 2
  store i64 0, ptr %28, align 8, !tbaa !15
  store i32 -143, ptr %8, align 4, !tbaa !11
  br label %75

29:                                               ; preds = %20
  %30 = load i64, ptr %7, align 8, !tbaa !9
  %31 = icmp eq i64 %30, 0
  br i1 %31, label %32, label %38

32:                                               ; preds = %29
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.psa_key_derivation_s, ptr %33, i32 0, i32 2
  %35 = load i64, ptr %34, align 8, !tbaa !15
  %36 = icmp eq i64 %35, 0
  br i1 %36, label %37, label %38

37:                                               ; preds = %32
  store i32 -143, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %91

38:                                               ; preds = %32, %29
  %39 = load i64, ptr %7, align 8, !tbaa !9
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.psa_key_derivation_s, ptr %40, i32 0, i32 2
  %42 = load i64, ptr %41, align 8, !tbaa !15
  %43 = sub i64 %42, %39
  store i64 %43, ptr %41, align 8, !tbaa !15
  %44 = load i32, ptr %9, align 4, !tbaa !11
  %45 = and i32 %44, -256
  %46 = icmp eq i32 %45, 536871168
  br i1 %46, label %47, label %57

47:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %48 = load i32, ptr %9, align 4, !tbaa !11
  %49 = and i32 %48, 255
  %50 = or i32 16777216, %49
  store i32 %50, ptr %11, align 4, !tbaa !11
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.psa_key_derivation_s, ptr %51, i32 0, i32 3
  %53 = load i32, ptr %11, align 4, !tbaa !11
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = load i64, ptr %7, align 8, !tbaa !9
  %56 = call i32 @psa_key_derivation_hkdf_read(ptr noundef %52, i32 noundef %53, ptr noundef %54, i64 noundef %55)
  store i32 %56, ptr %8, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %74

57:                                               ; preds = %38
  %58 = load i32, ptr %9, align 4, !tbaa !11
  %59 = and i32 %58, -256
  %60 = icmp eq i32 %59, 536871424
  br i1 %60, label %65, label %61

61:                                               ; preds = %57
  %62 = load i32, ptr %9, align 4, !tbaa !11
  %63 = and i32 %62, -256
  %64 = icmp eq i32 %63, 536871680
  br i1 %64, label %65, label %72

65:                                               ; preds = %61, %57
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.psa_key_derivation_s, ptr %66, i32 0, i32 3
  %68 = load i32, ptr %9, align 4, !tbaa !11
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = load i64, ptr %7, align 8, !tbaa !9
  %71 = call i32 @psa_key_derivation_tls12_prf_read(ptr noundef %67, i32 noundef %68, ptr noundef %69, i64 noundef %70)
  store i32 %71, ptr %8, align 4, !tbaa !11
  br label %73

72:                                               ; preds = %61
  store i32 -137, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %91

73:                                               ; preds = %65
  br label %74

74:                                               ; preds = %73, %47
  br label %75

75:                                               ; preds = %74, %26
  %76 = load i32, ptr %8, align 4, !tbaa !11
  %77 = icmp ne i32 %76, 0
  br i1 %77, label %78, label %89

78:                                               ; preds = %75
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %79 = load ptr, ptr %5, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.psa_key_derivation_s, ptr %79, i32 0, i32 0
  %81 = load i32, ptr %80, align 8, !tbaa !13
  store i32 %81, ptr %12, align 4, !tbaa !11
  %82 = load ptr, ptr %5, align 8, !tbaa !5
  %83 = call i32 @psa_key_derivation_abort(ptr noundef %82)
  %84 = load i32, ptr %12, align 4, !tbaa !11
  %85 = load ptr, ptr %5, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.psa_key_derivation_s, ptr %85, i32 0, i32 0
  store i32 %84, ptr %86, align 8, !tbaa !13
  %87 = load ptr, ptr %6, align 8, !tbaa !5
  %88 = load i64, ptr %7, align 8, !tbaa !9
  call void @llvm.memset.p0.i64(ptr align 1 %87, i8 33, i64 %88, i1 false)
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %89

89:                                               ; preds = %78, %75
  %90 = load i32, ptr %8, align 4, !tbaa !11
  store i32 %90, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %91

91:                                               ; preds = %89, %72, %37, %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %92 = load i32, ptr %4, align 4
  ret i32 %92
}

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

; Function Attrs: nounwind uwtable
declare hidden i32 @psa_key_derivation_tls12_prf_read(ptr noundef, i32 noundef, ptr noundef, i64 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 = !{!"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}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 0}
!14 = !{!"psa_key_derivation_s", !12, i64 0, !12, i64 4, !10, i64 8, !7, i64 16}
!15 = !{!14, !10, i64 8}


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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @psa_key_derivation_output_bytes(ptr noundef %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #1 {
  %4 = tail call i32 @psa_key_derivation_get_kdf_alg(ptr noundef %0)
  %5 = load i32, ptr %0, align 8, !tbaa !5
  %6 = icmp eq i32 %5, 0
  br i1 %6, label %28, label %7

7:                                                ; preds = %3
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = load i64, ptr %8, align 8, !tbaa !11
  %10 = icmp ult i64 %9, %2
  br i1 %10, label %.thread, label %11

.thread:                                          ; preds = %7
  store i64 0, ptr %8, align 8, !tbaa !11
  br label %25

11:                                               ; preds = %7
  %12 = or i64 %9, %2
  %or.cond = icmp eq i64 %12, 0
  br i1 %or.cond, label %28, label %13

13:                                               ; preds = %11
  %14 = sub i64 %9, %2
  store i64 %14, ptr %8, align 8, !tbaa !11
  %15 = and i32 %4, -256
  switch i32 %15, label %28 [
    i32 536871168, label %16
    i32 536871424, label %21
    i32 536871680, label %21
  ]

16:                                               ; preds = %13
  %17 = and i32 %4, 255
  %18 = or disjoint i32 %17, 16777216
  %19 = getelementptr inbounds i8, ptr %0, i64 16
  %20 = tail call i32 @psa_key_derivation_hkdf_read(ptr noundef nonnull %19, i32 noundef %18, ptr noundef %1, i64 noundef %2)
  br label %24

21:                                               ; preds = %13, %13
  %22 = getelementptr inbounds i8, ptr %0, i64 16
  %23 = tail call i32 @psa_key_derivation_tls12_prf_read(ptr noundef nonnull %22, i32 noundef %4, ptr noundef %1, i64 noundef %2)
  br label %24

24:                                               ; preds = %16, %21
  %.029 = phi i32 [ %20, %16 ], [ %23, %21 ]
  %.not = icmp eq i32 %.029, 0
  br i1 %.not, label %28, label %._crit_edge

._crit_edge:                                      ; preds = %24
  %.pre = load i32, ptr %0, align 8, !tbaa !5
  br label %25

25:                                               ; preds = %._crit_edge, %.thread
  %26 = phi i32 [ %5, %.thread ], [ %.pre, %._crit_edge ]
  %.02935 = phi i32 [ -143, %.thread ], [ %.029, %._crit_edge ]
  %27 = tail call i32 @psa_key_derivation_abort(ptr noundef nonnull %0)
  store i32 %26, ptr %0, align 8, !tbaa !5
  tail call void @llvm.memset.p0.i64(ptr align 1 %1, i8 33, i64 %2, i1 false)
  br label %28

28:                                               ; preds = %24, %25, %13, %11, %3
  %.0 = phi i32 [ -137, %3 ], [ -143, %11 ], [ -137, %13 ], [ %.02935, %25 ], [ 0, %24 ]
  ret i32 %.0
}

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

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

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

!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 = !{!6, !10, i64 8}


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