; LLVM IR from machinefi/psa-crypto-esp32 :: psa_layer (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.3 }
%union.anon.3 = type { %struct.psa_hkdf_key_derivation_t }
%struct.psa_hkdf_key_derivation_t = type { ptr, i64, i8, i8, i8, [32 x i8], [32 x i8], %struct.psa_mac_operation_s }
%struct.psa_mac_operation_s = type { i32, i8, i8, %union.psa_driver_mac_context_t }
%union.psa_driver_mac_context_t = type { %struct.iotex_psa_mac_operation_t }
%struct.iotex_psa_mac_operation_t = type { i32, %union.anon.0 }
%union.anon.0 = type { %struct.iotex_psa_hmac_operation_t }
%struct.iotex_psa_hmac_operation_t = type { i32, %struct.psa_hash_operation_s, [64 x i8] }
%struct.psa_hash_operation_s = type { i32, %union.psa_driver_hash_context_t }
%union.psa_driver_hash_context_t = type { %struct.iotex_psa_hash_operation_t }
%struct.iotex_psa_hash_operation_t = type { i32, %union.anon }
%union.anon = type { %struct.iotex_sha256_context }
%struct.iotex_sha256_context = type { ptr }
%struct.psa_tls12_prf_key_derivation_s = type { i8, i8, i32, ptr, i64, ptr, i64, ptr, i64, ptr, i64, [32 x i8], [32 x 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

declare void @iotex_platform_zeroize(ptr noundef, i64 noundef) #1

; Function Attrs: nounwind
declare void @free(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @psa_mac_abort(ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local i32 @psa_key_derivation_abort(ptr noundef %0) #3 {
  %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 %119

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

14:                                               ; preds = %10
  %15 = load i32, ptr %4, align 4, !tbaa !9
  %16 = and i32 %15, -256
  %17 = icmp eq i32 %16, 134218752
  br i1 %17, label %22, label %18

18:                                               ; preds = %14
  %19 = load i32, ptr %4, align 4, !tbaa !9
  %20 = and i32 %19, -256
  %21 = icmp eq i32 %20, 134219008
  br i1 %21, label %22, label %31

22:                                               ; preds = %18, %14, %10
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.psa_key_derivation_s, ptr %23, i32 0, i32 3
  %25 = getelementptr inbounds %struct.psa_hkdf_key_derivation_t, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !11
  call void @free(ptr noundef %26) #4
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.psa_key_derivation_s, ptr %27, i32 0, i32 3
  %29 = getelementptr inbounds %struct.psa_hkdf_key_derivation_t, ptr %28, i32 0, i32 7
  %30 = call i32 @psa_mac_abort(ptr noundef %29)
  store i32 %30, ptr %3, align 4, !tbaa !9
  br label %118

31:                                               ; preds = %18
  %32 = load i32, ptr %4, align 4, !tbaa !9
  %33 = and i32 %32, -256
  %34 = icmp eq i32 %33, 134218240
  br i1 %34, label %39, label %35

35:                                               ; preds = %31
  %36 = load i32, ptr %4, align 4, !tbaa !9
  %37 = and i32 %36, -256
  %38 = icmp eq i32 %37, 134218496
  br i1 %38, label %39, label %116

39:                                               ; preds = %35, %31
  %40 = load ptr, ptr %2, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.psa_key_derivation_s, ptr %40, i32 0, i32 3
  %42 = getelementptr inbounds %struct.psa_tls12_prf_key_derivation_s, ptr %41, i32 0, i32 3
  %43 = load ptr, ptr %42, align 8, !tbaa !11
  %44 = icmp ne ptr %43, null
  br i1 %44, label %45, label %58

45:                                               ; preds = %39
  %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
  %50 = load ptr, ptr %2, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.psa_key_derivation_s, ptr %50, i32 0, i32 3
  %52 = getelementptr inbounds %struct.psa_tls12_prf_key_derivation_s, ptr %51, i32 0, i32 4
  %53 = load i64, ptr %52, align 8, !tbaa !11
  call void @iotex_platform_zeroize(ptr noundef %49, i64 noundef %53)
  %54 = load ptr, ptr %2, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.psa_key_derivation_s, ptr %54, i32 0, i32 3
  %56 = getelementptr inbounds %struct.psa_tls12_prf_key_derivation_s, ptr %55, i32 0, i32 3
  %57 = load ptr, ptr %56, align 8, !tbaa !11
  call void @free(ptr noundef %57) #4
  br label %58

58:                                               ; preds = %45, %39
  %59 = load ptr, ptr %2, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.psa_key_derivation_s, ptr %59, i32 0, i32 3
  %61 = getelementptr inbounds %struct.psa_tls12_prf_key_derivation_s, ptr %60, i32 0, i32 5
  %62 = load ptr, ptr %61, align 8, !tbaa !11
  %63 = icmp ne ptr %62, null
  br i1 %63, label %64, label %77

64:                                               ; preds = %58
  %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
  %69 = load ptr, ptr %2, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.psa_key_derivation_s, ptr %69, i32 0, i32 3
  %71 = getelementptr inbounds %struct.psa_tls12_prf_key_derivation_s, ptr %70, i32 0, i32 6
  %72 = load i64, ptr %71, align 8, !tbaa !11
  call void @iotex_platform_zeroize(ptr noundef %68, i64 noundef %72)
  %73 = load ptr, ptr %2, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.psa_key_derivation_s, ptr %73, i32 0, i32 3
  %75 = getelementptr inbounds %struct.psa_tls12_prf_key_derivation_s, ptr %74, i32 0, i32 5
  %76 = load ptr, ptr %75, align 8, !tbaa !11
  call void @free(ptr noundef %76) #4
  br label %77

77:                                               ; preds = %64, %58
  %78 = load ptr, ptr %2, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.psa_key_derivation_s, ptr %78, i32 0, i32 3
  %80 = getelementptr inbounds %struct.psa_tls12_prf_key_derivation_s, ptr %79, i32 0, i32 7
  %81 = load ptr, ptr %80, align 8, !tbaa !11
  %82 = icmp ne ptr %81, null
  br i1 %82, label %83, label %96

83:                                               ; preds = %77
  %84 = load ptr, ptr %2, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.psa_key_derivation_s, ptr %84, i32 0, i32 3
  %86 = getelementptr inbounds %struct.psa_tls12_prf_key_derivation_s, ptr %85, i32 0, i32 7
  %87 = load ptr, ptr %86, align 8, !tbaa !11
  %88 = load ptr, ptr %2, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.psa_key_derivation_s, ptr %88, i32 0, i32 3
  %90 = getelementptr inbounds %struct.psa_tls12_prf_key_derivation_s, ptr %89, i32 0, i32 8
  %91 = load i64, ptr %90, align 8, !tbaa !11
  call void @iotex_platform_zeroize(ptr noundef %87, i64 noundef %91)
  %92 = load ptr, ptr %2, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.psa_key_derivation_s, ptr %92, i32 0, i32 3
  %94 = getelementptr inbounds %struct.psa_tls12_prf_key_derivation_s, ptr %93, i32 0, i32 7
  %95 = load ptr, ptr %94, align 8, !tbaa !11
  call void @free(ptr noundef %95) #4
  br label %96

96:                                               ; preds = %83, %77
  %97 = load ptr, ptr %2, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.psa_key_derivation_s, ptr %97, i32 0, i32 3
  %99 = getelementptr inbounds %struct.psa_tls12_prf_key_derivation_s, ptr %98, i32 0, i32 9
  %100 = load ptr, ptr %99, align 8, !tbaa !11
  %101 = icmp ne ptr %100, null
  br i1 %101, label %102, label %115

102:                                              ; preds = %96
  %103 = load ptr, ptr %2, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.psa_key_derivation_s, ptr %103, i32 0, i32 3
  %105 = getelementptr inbounds %struct.psa_tls12_prf_key_derivation_s, ptr %104, i32 0, i32 9
  %106 = load ptr, ptr %105, align 8, !tbaa !11
  %107 = load ptr, ptr %2, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct.psa_key_derivation_s, ptr %107, i32 0, i32 3
  %109 = getelementptr inbounds %struct.psa_tls12_prf_key_derivation_s, ptr %108, i32 0, i32 10
  %110 = load i64, ptr %109, align 8, !tbaa !11
  call void @iotex_platform_zeroize(ptr noundef %106, i64 noundef %110)
  %111 = load ptr, ptr %2, align 8, !tbaa !5
  %112 = getelementptr inbounds %struct.psa_key_derivation_s, ptr %111, i32 0, i32 3
  %113 = getelementptr inbounds %struct.psa_tls12_prf_key_derivation_s, ptr %112, i32 0, i32 9
  %114 = load ptr, ptr %113, align 8, !tbaa !11
  call void @free(ptr noundef %114) #4
  br label %115

115:                                              ; preds = %102, %96
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %117

116:                                              ; preds = %35
  store i32 -137, ptr %3, align 4, !tbaa !9
  br label %117

117:                                              ; preds = %116, %115
  br label %118

118:                                              ; preds = %117, %22
  br label %119

119:                                              ; preds = %118, %9
  %120 = load ptr, ptr %2, align 8, !tbaa !5
  call void @iotex_platform_zeroize(ptr noundef %120, i64 noundef 216)
  %121 = 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 %121
}

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

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

declare void @iotex_platform_zeroize(ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #1

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

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

4:                                                ; preds = %1
  %5 = add i32 %2, -134217984
  %6 = lshr i32 %5, 8
  switch i32 %6, label %40 [
    i32 0, label %7
    i32 3, label %7
    i32 4, label %7
    i32 1, label %12
    i32 2, label %12
  ]

7:                                                ; preds = %4, %4, %4
  %8 = getelementptr inbounds i8, ptr %0, i64 16
  %9 = load ptr, ptr %8, align 8, !tbaa !5
  tail call void @free(ptr noundef %9) #3
  %10 = getelementptr inbounds i8, ptr %0, i64 104
  %11 = tail call i32 @psa_mac_abort(ptr noundef nonnull %10)
  br label %40

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

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

19:                                               ; preds = %15, %12
  %20 = getelementptr inbounds i8, ptr %0, i64 40
  %21 = load ptr, ptr %20, align 8, !tbaa !5
  %.not32 = icmp eq ptr %21, null
  br i1 %.not32, label %26, label %22

22:                                               ; preds = %19
  %23 = getelementptr inbounds i8, ptr %0, i64 48
  %24 = load i64, ptr %23, align 8, !tbaa !5
  tail call void @iotex_platform_zeroize(ptr noundef nonnull %21, i64 noundef %24) #3
  %25 = load ptr, ptr %20, align 8, !tbaa !5
  tail call void @free(ptr noundef %25) #3
  br label %26

26:                                               ; preds = %22, %19
  %27 = getelementptr inbounds i8, ptr %0, i64 56
  %28 = load ptr, ptr %27, align 8, !tbaa !5
  %.not33 = icmp eq ptr %28, null
  br i1 %.not33, label %33, label %29

29:                                               ; preds = %26
  %30 = getelementptr inbounds i8, ptr %0, i64 64
  %31 = load i64, ptr %30, align 8, !tbaa !5
  tail call void @iotex_platform_zeroize(ptr noundef nonnull %28, i64 noundef %31) #3
  %32 = load ptr, ptr %27, align 8, !tbaa !5
  tail call void @free(ptr noundef %32) #3
  br label %33

33:                                               ; preds = %29, %26
  %34 = getelementptr inbounds i8, ptr %0, i64 72
  %35 = load ptr, ptr %34, align 8, !tbaa !5
  %.not34 = icmp eq ptr %35, null
  br i1 %.not34, label %40, label %36

36:                                               ; preds = %33
  %37 = getelementptr inbounds i8, ptr %0, i64 80
  %38 = load i64, ptr %37, align 8, !tbaa !5
  tail call void @iotex_platform_zeroize(ptr noundef nonnull %35, i64 noundef %38) #3
  %39 = load ptr, ptr %34, align 8, !tbaa !5
  tail call void @free(ptr noundef %39) #3
  br label %40

40:                                               ; preds = %4, %33, %36, %7, %1
  %.0 = phi i32 [ 0, %1 ], [ %11, %7 ], [ 0, %36 ], [ 0, %33 ], [ -137, %4 ]
  tail call void @iotex_platform_zeroize(ptr noundef %0, i64 noundef 216) #3
  ret i32 %.0
}

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

attributes #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 #1 = { 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 #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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


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