; 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_global_data_t = type { ptr, ptr, %struct.mbedtls_entropy_context, %struct.mbedtls_ctr_drbg_context, i8 }
%struct.mbedtls_entropy_context = type { i32, %struct.mbedtls_sha512_context, i32, [20 x %struct.mbedtls_entropy_source_state] }
%struct.mbedtls_sha512_context = type { [2 x i64], [8 x i64], [128 x i8], i32 }
%struct.mbedtls_entropy_source_state = type { ptr, ptr, i64, i64, i32 }
%struct.mbedtls_ctr_drbg_context = type { [16 x i8], i32, i32, i64, i32, %struct.mbedtls_aes_context, ptr, ptr }
%struct.mbedtls_aes_context = type { i32, ptr, [68 x i32] }

@global_data = external hidden global %struct.psa_global_data_t, align 8
@__const.psa_crypto_init.drbg_seed = external hidden unnamed_addr constant [4 x i8], align 1

; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; 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 @mbedtls_to_psa_error(i32 noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @mbedtls_psa_crypto_free() #2

; Function Attrs: nounwind uwtable
define dso_local i32 @psa_crypto_init() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca [4 x i8], align 1
  %4 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %3, ptr align 1 @__const.psa_crypto_init.drbg_seed, i64 4, i1 false)
  %5 = load i8, ptr getelementptr inbounds (%struct.psa_global_data_t, ptr @global_data, i32 0, i32 4), align 8
  %6 = and i8 %5, 1
  %7 = zext i8 %6 to i32
  %8 = icmp ne i32 %7, 0
  br i1 %8, label %9, label %10

9:                                                ; preds = %0
  store i32 0, ptr %1, align 4
  store i32 1, ptr %4, align 4
  br label %47

10:                                               ; preds = %0
  %11 = load ptr, ptr @global_data, align 8, !tbaa !5
  %12 = icmp eq ptr %11, null
  br i1 %12, label %13, label %14

13:                                               ; preds = %10
  store ptr @mbedtls_entropy_init, ptr @global_data, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %13, %10
  %15 = load ptr, ptr getelementptr inbounds (%struct.psa_global_data_t, ptr @global_data, i32 0, i32 1), align 8, !tbaa !16
  %16 = icmp eq ptr %15, null
  br i1 %16, label %17, label %18

17:                                               ; preds = %14
  store ptr @mbedtls_entropy_free, ptr getelementptr inbounds (%struct.psa_global_data_t, ptr @global_data, i32 0, i32 1), align 8, !tbaa !16
  br label %18

18:                                               ; preds = %17, %14
  %19 = load ptr, ptr @global_data, align 8, !tbaa !5
  call void %19(ptr noundef getelementptr inbounds (%struct.psa_global_data_t, ptr @global_data, i32 0, i32 2))
  call void @mbedtls_ctr_drbg_init(ptr noundef getelementptr inbounds (%struct.psa_global_data_t, ptr @global_data, i32 0, i32 3))
  %20 = load i8, ptr getelementptr inbounds (%struct.psa_global_data_t, ptr @global_data, i32 0, i32 4), align 8
  %21 = and i8 %20, -7
  %22 = or i8 %21, 2
  store i8 %22, ptr getelementptr inbounds (%struct.psa_global_data_t, ptr @global_data, i32 0, i32 4), align 8
  %23 = getelementptr inbounds [4 x i8], ptr %3, i64 0, i64 0
  %24 = call i32 @mbedtls_ctr_drbg_seed(ptr noundef getelementptr inbounds (%struct.psa_global_data_t, ptr @global_data, i32 0, i32 3), ptr noundef @mbedtls_entropy_func, ptr noundef getelementptr inbounds (%struct.psa_global_data_t, ptr @global_data, i32 0, i32 2), ptr noundef %23, i64 noundef 3)
  %25 = call i32 @mbedtls_to_psa_error(i32 noundef %24)
  store i32 %25, ptr %2, align 4, !tbaa !17
  %26 = load i32, ptr %2, align 4, !tbaa !17
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %28, label %29

28:                                               ; preds = %18
  br label %41

29:                                               ; preds = %18
  %30 = load i8, ptr getelementptr inbounds (%struct.psa_global_data_t, ptr @global_data, i32 0, i32 4), align 8
  %31 = and i8 %30, -7
  %32 = or i8 %31, 4
  store i8 %32, ptr getelementptr inbounds (%struct.psa_global_data_t, ptr @global_data, i32 0, i32 4), align 8
  %33 = call i32 @psa_initialize_key_slots()
  store i32 %33, ptr %2, align 4, !tbaa !17
  %34 = load i32, ptr %2, align 4, !tbaa !17
  %35 = icmp ne i32 %34, 0
  br i1 %35, label %36, label %37

36:                                               ; preds = %29
  br label %41

37:                                               ; preds = %29
  %38 = load i8, ptr getelementptr inbounds (%struct.psa_global_data_t, ptr @global_data, i32 0, i32 4), align 8
  %39 = and i8 %38, -2
  %40 = or i8 %39, 1
  store i8 %40, ptr getelementptr inbounds (%struct.psa_global_data_t, ptr @global_data, i32 0, i32 4), align 8
  br label %41

41:                                               ; preds = %37, %36, %28
  %42 = load i32, ptr %2, align 4, !tbaa !17
  %43 = icmp ne i32 %42, 0
  br i1 %43, label %44, label %45

44:                                               ; preds = %41
  call void @mbedtls_psa_crypto_free()
  br label %45

45:                                               ; preds = %44, %41
  %46 = load i32, ptr %2, align 4, !tbaa !17
  store i32 %46, ptr %1, align 4
  store i32 1, ptr %4, align 4
  br label %47

47:                                               ; preds = %45, %9
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  %48 = load i32, ptr %1, align 4
  ret i32 %48
}

declare void @mbedtls_entropy_init(ptr noundef) #3

declare void @mbedtls_entropy_free(ptr noundef) #3

declare void @mbedtls_ctr_drbg_init(ptr noundef) #3

declare i32 @mbedtls_ctr_drbg_seed(ptr noundef, ptr noundef, ptr noundef, ptr noundef, i64 noundef) #3

declare i32 @mbedtls_entropy_func(ptr noundef, ptr noundef, i64 noundef) #3

declare i32 @psa_initialize_key_slots() #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !7, i64 0}
!6 = !{!"", !7, i64 0, !7, i64 8, !10, i64 16, !13, i64 1048, !11, i64 1392, !11, i64 1392}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"mbedtls_entropy_context", !11, i64 0, !12, i64 8, !11, i64 224, !8, i64 232}
!11 = !{!"int", !8, i64 0}
!12 = !{!"mbedtls_sha512_context", !8, i64 0, !8, i64 16, !8, i64 80, !11, i64 208}
!13 = !{!"mbedtls_ctr_drbg_context", !8, i64 0, !11, i64 16, !11, i64 20, !14, i64 24, !11, i64 32, !15, i64 40, !7, i64 328, !7, i64 336}
!14 = !{!"long", !8, i64 0}
!15 = !{!"mbedtls_aes_context", !11, i64 0, !7, i64 8, !8, i64 16}
!16 = !{!6, !7, i64 8}
!17 = !{!11, !11, 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"

%struct.psa_global_data_t = type { ptr, ptr, %struct.mbedtls_entropy_context, %struct.mbedtls_ctr_drbg_context, i8 }
%struct.mbedtls_entropy_context = type { i32, %struct.mbedtls_sha512_context, i32, [20 x %struct.mbedtls_entropy_source_state] }
%struct.mbedtls_sha512_context = type { [2 x i64], [8 x i64], [128 x i8], i32 }
%struct.mbedtls_entropy_source_state = type { ptr, ptr, i64, i64, i32 }
%struct.mbedtls_ctr_drbg_context = type { [16 x i8], i32, i32, i64, i32, %struct.mbedtls_aes_context, ptr, ptr }
%struct.mbedtls_aes_context = type { i32, ptr, [68 x i32] }

@global_data = external hidden global %struct.psa_global_data_t, align 8
@__const.psa_crypto_init.drbg_seed = external hidden unnamed_addr constant [4 x i8], align 1

; 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 @mbedtls_to_psa_error(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @mbedtls_psa_crypto_free() local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @psa_crypto_init() local_unnamed_addr #1 {
  %1 = alloca [4 x i8], align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #3
  %2 = load i32, ptr @__const.psa_crypto_init.drbg_seed, align 1
  store i32 %2, ptr %1, align 4
  %3 = load i8, ptr getelementptr inbounds (i8, ptr @global_data, i64 1392), align 8
  %4 = and i8 %3, 1
  %.not = icmp eq i8 %4, 0
  br i1 %.not, label %5, label %29

5:                                                ; preds = %0
  %6 = load ptr, ptr @global_data, align 8, !tbaa !5
  %7 = icmp eq ptr %6, null
  br i1 %7, label %8, label %9

8:                                                ; preds = %5
  store ptr @mbedtls_entropy_init, ptr @global_data, align 8, !tbaa !5
  br label %9

9:                                                ; preds = %8, %5
  %10 = phi ptr [ @mbedtls_entropy_init, %8 ], [ %6, %5 ]
  %11 = load ptr, ptr getelementptr inbounds (i8, ptr @global_data, i64 8), align 8, !tbaa !16
  %12 = icmp eq ptr %11, null
  br i1 %12, label %13, label %14

13:                                               ; preds = %9
  store ptr @mbedtls_entropy_free, ptr getelementptr inbounds (i8, ptr @global_data, i64 8), align 8, !tbaa !16
  br label %14

14:                                               ; preds = %13, %9
  tail call void %10(ptr noundef nonnull getelementptr inbounds (i8, ptr @global_data, i64 16)) #3
  tail call void @mbedtls_ctr_drbg_init(ptr noundef nonnull getelementptr inbounds (i8, ptr @global_data, i64 1048)) #3
  %15 = load i8, ptr getelementptr inbounds (i8, ptr @global_data, i64 1392), align 8
  %16 = and i8 %15, -7
  %17 = or disjoint i8 %16, 2
  store i8 %17, ptr getelementptr inbounds (i8, ptr @global_data, i64 1392), align 8
  %18 = call i32 @mbedtls_ctr_drbg_seed(ptr noundef nonnull getelementptr inbounds (i8, ptr @global_data, i64 1048), ptr noundef nonnull @mbedtls_entropy_func, ptr noundef nonnull getelementptr inbounds (i8, ptr @global_data, i64 16), ptr noundef nonnull %1, i64 noundef 3) #3
  %19 = call i32 @mbedtls_to_psa_error(i32 noundef %18)
  %.not8 = icmp eq i32 %19, 0
  br i1 %.not8, label %20, label %28

20:                                               ; preds = %14
  %21 = load i8, ptr getelementptr inbounds (i8, ptr @global_data, i64 1392), align 8
  %22 = and i8 %21, -7
  %23 = or disjoint i8 %22, 4
  store i8 %23, ptr getelementptr inbounds (i8, ptr @global_data, i64 1392), align 8
  %24 = call i32 @psa_initialize_key_slots() #3
  %.not9 = icmp eq i32 %24, 0
  br i1 %.not9, label %25, label %28

25:                                               ; preds = %20
  %26 = load i8, ptr getelementptr inbounds (i8, ptr @global_data, i64 1392), align 8
  %27 = or i8 %26, 1
  store i8 %27, ptr getelementptr inbounds (i8, ptr @global_data, i64 1392), align 8
  br label %29

28:                                               ; preds = %14, %20
  %.0.ph = phi i32 [ %24, %20 ], [ %19, %14 ]
  call void @mbedtls_psa_crypto_free()
  br label %29

29:                                               ; preds = %25, %28, %0
  %.05 = phi i32 [ 0, %0 ], [ %.0.ph, %28 ], [ 0, %25 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #3
  ret i32 %.05
}

declare void @mbedtls_entropy_init(ptr noundef) #2

declare void @mbedtls_entropy_free(ptr noundef) #2

declare void @mbedtls_ctr_drbg_init(ptr noundef) local_unnamed_addr #2

declare i32 @mbedtls_ctr_drbg_seed(ptr noundef, ptr noundef, ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

declare i32 @mbedtls_entropy_func(ptr noundef, ptr noundef, i64 noundef) #2

declare i32 @psa_initialize_key_slots() local_unnamed_addr #2

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 = { "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, !7, i64 0}
!6 = !{!"", !7, i64 0, !7, i64 8, !10, i64 16, !13, i64 1048, !11, i64 1392, !11, i64 1392}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"mbedtls_entropy_context", !11, i64 0, !12, i64 8, !11, i64 224, !8, i64 232}
!11 = !{!"int", !8, i64 0}
!12 = !{!"mbedtls_sha512_context", !8, i64 0, !8, i64 16, !8, i64 80, !11, i64 208}
!13 = !{!"mbedtls_ctr_drbg_context", !8, i64 0, !11, i64 16, !11, i64 20, !14, i64 24, !11, i64 32, !15, i64 40, !7, i64 328, !7, i64 336}
!14 = !{!"long", !8, i64 0}
!15 = !{!"mbedtls_aes_context", !11, i64 0, !7, i64 8, !8, i64 16}
!16 = !{!6, !7, i64 8}


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