; 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 }
%struct.psa_hkdf_key_derivation_t = type { ptr, i64, %struct.psa_hmac_internal_data, [64 x i8], [64 x i8], i8, i8, i8 }

; 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
declare void @free(ptr noundef) #1

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

declare void @mbedtls_platform_zeroize(ptr noundef, i64 noundef) #3

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

9:                                                ; preds = %1
  br label %77

10:                                               ; preds = %1
  %11 = load i32, ptr %4, align 4, !tbaa !9
  %12 = and i32 %11, -256
  %13 = icmp eq i32 %12, 536871168
  br i1 %13, label %14, label %23

14:                                               ; preds = %10
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.psa_key_derivation_s, ptr %15, i32 0, i32 3
  %17 = getelementptr inbounds %struct.psa_hkdf_key_derivation_t, ptr %16, i32 0, i32 0
  %18 = load ptr, ptr %17, align 8, !tbaa !11
  call void @free(ptr noundef %18) #4
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.psa_key_derivation_s, ptr %19, i32 0, i32 3
  %21 = getelementptr inbounds %struct.psa_hkdf_key_derivation_t, ptr %20, i32 0, i32 2
  %22 = call i32 @psa_hmac_abort_internal(ptr noundef %21)
  store i32 %22, ptr %3, align 4, !tbaa !9
  br label %76

23:                                               ; preds = %10
  %24 = load i32, ptr %4, align 4, !tbaa !9
  %25 = and i32 %24, -256
  %26 = icmp eq i32 %25, 536871424
  br i1 %26, label %31, label %27

27:                                               ; preds = %23
  %28 = load i32, ptr %4, align 4, !tbaa !9
  %29 = and i32 %28, -256
  %30 = icmp eq i32 %29, 536871680
  br i1 %30, label %31, label %74

31:                                               ; preds = %27, %23
  %32 = load ptr, ptr %2, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.psa_key_derivation_s, ptr %32, i32 0, i32 3
  %34 = getelementptr inbounds %struct.psa_tls12_prf_key_derivation_s, ptr %33, i32 0, i32 3
  %35 = load ptr, ptr %34, align 8, !tbaa !11
  %36 = icmp ne ptr %35, null
  br i1 %36, label %37, label %50

37:                                               ; preds = %31
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.psa_key_derivation_s, ptr %38, i32 0, i32 3
  %40 = getelementptr inbounds %struct.psa_tls12_prf_key_derivation_s, ptr %39, i32 0, i32 3
  %41 = load ptr, ptr %40, align 8, !tbaa !11
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.psa_key_derivation_s, ptr %42, i32 0, i32 3
  %44 = getelementptr inbounds %struct.psa_tls12_prf_key_derivation_s, ptr %43, i32 0, i32 4
  %45 = load i64, ptr %44, align 8, !tbaa !11
  call void @mbedtls_platform_zeroize(ptr noundef %41, i64 noundef %45)
  %46 = load ptr, ptr %2, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.psa_key_derivation_s, ptr %46, i32 0, i32 3
  %48 = getelementptr inbounds %struct.psa_tls12_prf_key_derivation_s, ptr %47, i32 0, i32 3
  %49 = load ptr, ptr %48, align 8, !tbaa !11
  call void @free(ptr noundef %49) #4
  br label %50

50:                                               ; preds = %37, %31
  %51 = load ptr, ptr %2, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.psa_key_derivation_s, ptr %51, i32 0, i32 3
  %53 = getelementptr inbounds %struct.psa_tls12_prf_key_derivation_s, ptr %52, i32 0, i32 5
  %54 = load ptr, ptr %53, align 8, !tbaa !11
  %55 = icmp ne ptr %54, null
  br i1 %55, label %56, label %69

56:                                               ; preds = %50
  %57 = load ptr, ptr %2, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.psa_key_derivation_s, ptr %57, i32 0, i32 3
  %59 = getelementptr inbounds %struct.psa_tls12_prf_key_derivation_s, ptr %58, i32 0, i32 5
  %60 = load ptr, ptr %59, align 8, !tbaa !11
  %61 = load ptr, ptr %2, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.psa_key_derivation_s, ptr %61, i32 0, i32 3
  %63 = getelementptr inbounds %struct.psa_tls12_prf_key_derivation_s, ptr %62, i32 0, i32 6
  %64 = load i64, ptr %63, align 8, !tbaa !11
  call void @mbedtls_platform_zeroize(ptr noundef %60, i64 noundef %64)
  %65 = load ptr, ptr %2, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.psa_key_derivation_s, ptr %65, i32 0, i32 3
  %67 = getelementptr inbounds %struct.psa_tls12_prf_key_derivation_s, ptr %66, i32 0, i32 5
  %68 = load ptr, ptr %67, align 8, !tbaa !11
  call void @free(ptr noundef %68) #4
  br label %69

69:                                               ; preds = %56, %50
  %70 = load ptr, ptr %2, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.psa_key_derivation_s, ptr %70, i32 0, i32 3
  %72 = getelementptr inbounds %struct.psa_tls12_prf_key_derivation_s, ptr %71, i32 0, i32 7
  %73 = call i32 @psa_hmac_abort_internal(ptr noundef %72)
  store i32 %73, ptr %3, align 4, !tbaa !9
  br label %75

74:                                               ; preds = %27
  store i32 -137, ptr %3, align 4, !tbaa !9
  br label %75

75:                                               ; preds = %74, %69
  br label %76

76:                                               ; preds = %75, %14
  br label %77

77:                                               ; preds = %76, %9
  %78 = load ptr, ptr %2, align 8, !tbaa !5
  call void @mbedtls_platform_zeroize(ptr noundef %78, i64 noundef 536)
  %79 = load i32, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  ret i32 %79
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind "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 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 = { "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 #4 = { 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 = !{!"int", !7, i64 0}
!11 = !{!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 nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #0

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

declare void @mbedtls_platform_zeroize(ptr noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local i32 @psa_key_derivation_abort(ptr noundef %0) local_unnamed_addr #1 {
  %2 = tail call i32 @psa_key_derivation_get_kdf_alg(ptr noundef %0)
  %3 = icmp eq i32 %2, 0
  br i1 %3, label %24, label %4

4:                                                ; preds = %1
  %5 = and i32 %2, -256
  switch i32 %5, label %24 [
    i32 536871168, label %6
    i32 536871424, label %8
    i32 536871680, label %8
  ]

6:                                                ; preds = %4
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  br label %.sink.split.sink.split

8:                                                ; preds = %4, %4
  %9 = getelementptr inbounds i8, ptr %0, i64 24
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  %.not = icmp eq ptr %10, null
  br i1 %.not, label %15, label %11

11:                                               ; preds = %8
  %12 = getelementptr inbounds i8, ptr %0, i64 32
  %13 = load i64, ptr %12, align 8, !tbaa !5
  tail call void @mbedtls_platform_zeroize(ptr noundef nonnull %10, i64 noundef %13) #3
  %14 = load ptr, ptr %9, align 8, !tbaa !5
  tail call void @free(ptr noundef %14) #3
  br label %15

15:                                               ; preds = %11, %8
  %16 = getelementptr inbounds i8, ptr %0, i64 40
  %17 = load ptr, ptr %16, align 8, !tbaa !5
  %.not21 = icmp eq ptr %17, null
  br i1 %.not21, label %.sink.split, label %18

18:                                               ; preds = %15
  %19 = getelementptr inbounds i8, ptr %0, i64 48
  %20 = load i64, ptr %19, align 8, !tbaa !5
  tail call void @mbedtls_platform_zeroize(ptr noundef nonnull %17, i64 noundef %20) #3
  br label %.sink.split.sink.split

.sink.split.sink.split:                           ; preds = %6, %18
  %.sink23 = phi ptr [ %16, %18 ], [ %7, %6 ]
  %.sink22.ph = phi i64 [ 56, %18 ], [ 32, %6 ]
  %21 = load ptr, ptr %.sink23, align 8, !tbaa !5
  tail call void @free(ptr noundef %21) #3
  br label %.sink.split

.sink.split:                                      ; preds = %.sink.split.sink.split, %15
  %.sink22 = phi i64 [ 56, %15 ], [ %.sink22.ph, %.sink.split.sink.split ]
  %22 = getelementptr inbounds i8, ptr %0, i64 %.sink22
  %23 = tail call i32 @psa_hmac_abort_internal(ptr noundef nonnull %22)
  br label %24

24:                                               ; preds = %.sink.split, %4, %1
  %.0 = phi i32 [ 0, %1 ], [ -137, %4 ], [ %23, %.sink.split ]
  tail call void @mbedtls_platform_zeroize(ptr noundef %0, i64 noundef 536) #3
  ret i32 %.0
}

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

attributes #0 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


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