; LLVM IR from machinefi/psa-crypto-esp32 :: psa_layer (psa_its_nvs)

; 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_its_file_header_t = type { [8 x i8], [4 x i8], [4 x i8] }
%struct._nvs_drv = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.psa_storage_info_t = type { i32, i32 }

@its_nvs = external dso_local global ptr, align 8
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [9 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @psa_its_get_info(i64 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca [13 x i8], align 1
  %6 = alloca i32, align 4
  %7 = alloca %struct.psa_its_file_header_t, align 1
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  store i64 %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 13, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  store i64 16, ptr %9, align 8, !tbaa !5
  %10 = load i64, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds [13 x i8], ptr %5, i64 0, i64 0
  call void @psa_its_fill_filename(i64 noundef %10, ptr noundef %11)
  %12 = load ptr, ptr @its_nvs, align 8, !tbaa !9
  %13 = getelementptr inbounds %struct._nvs_drv, ptr %12, i32 0, i32 0
  %14 = load ptr, ptr %13, align 8, !tbaa !13
  %15 = getelementptr inbounds [13 x i8], ptr %5, i64 0, i64 0
  %16 = call i32 %14(ptr noundef %15, i32 noundef 1, ptr noundef %8)
  store i32 %16, ptr %6, align 4, !tbaa !11
  %17 = load i32, ptr %6, align 4, !tbaa !11
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %19, label %20

19:                                               ; preds = %2
  store i32 -140, ptr %6, align 4, !tbaa !11
  br label %84

20:                                               ; preds = %2
  %21 = load ptr, ptr @its_nvs, align 8, !tbaa !9
  %22 = getelementptr inbounds %struct._nvs_drv, ptr %21, i32 0, i32 3
  %23 = load ptr, ptr %22, align 8, !tbaa !15
  %24 = load i32, ptr %8, align 4, !tbaa !11
  %25 = call i32 %23(i32 noundef %24, ptr noundef @.str, ptr noundef %7, ptr noundef %9)
  store i32 %25, ptr %6, align 4, !tbaa !11
  %26 = load i32, ptr %6, align 4, !tbaa !11
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %28, label %29

28:                                               ; preds = %20
  store i32 -140, ptr %6, align 4, !tbaa !11
  br label %84

29:                                               ; preds = %20
  %30 = getelementptr inbounds %struct.psa_its_file_header_t, ptr %7, i32 0, i32 0
  %31 = getelementptr inbounds [8 x i8], ptr %30, i64 0, i64 0
  %32 = call i32 @memcmp(ptr noundef %31, ptr noundef @.str.1, i64 noundef 8) #4
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %34, label %35

34:                                               ; preds = %29
  store i32 -140, ptr %6, align 4, !tbaa !11
  br label %84

35:                                               ; preds = %29
  %36 = getelementptr inbounds %struct.psa_its_file_header_t, ptr %7, i32 0, i32 1
  %37 = getelementptr inbounds [4 x i8], ptr %36, i64 0, i64 0
  %38 = load i8, ptr %37, align 1, !tbaa !16
  %39 = zext i8 %38 to i32
  %40 = getelementptr inbounds %struct.psa_its_file_header_t, ptr %7, i32 0, i32 1
  %41 = getelementptr inbounds [4 x i8], ptr %40, i64 0, i64 1
  %42 = load i8, ptr %41, align 1, !tbaa !16
  %43 = zext i8 %42 to i32
  %44 = shl i32 %43, 8
  %45 = or i32 %39, %44
  %46 = getelementptr inbounds %struct.psa_its_file_header_t, ptr %7, i32 0, i32 1
  %47 = getelementptr inbounds [4 x i8], ptr %46, i64 0, i64 2
  %48 = load i8, ptr %47, align 1, !tbaa !16
  %49 = zext i8 %48 to i32
  %50 = shl i32 %49, 16
  %51 = or i32 %45, %50
  %52 = getelementptr inbounds %struct.psa_its_file_header_t, ptr %7, i32 0, i32 1
  %53 = getelementptr inbounds [4 x i8], ptr %52, i64 0, i64 3
  %54 = load i8, ptr %53, align 1, !tbaa !16
  %55 = zext i8 %54 to i32
  %56 = shl i32 %55, 24
  %57 = or i32 %51, %56
  %58 = load ptr, ptr %4, align 8, !tbaa !9
  %59 = getelementptr inbounds %struct.psa_storage_info_t, ptr %58, i32 0, i32 0
  store i32 %57, ptr %59, align 4, !tbaa !17
  %60 = getelementptr inbounds %struct.psa_its_file_header_t, ptr %7, i32 0, i32 2
  %61 = getelementptr inbounds [4 x i8], ptr %60, i64 0, i64 0
  %62 = load i8, ptr %61, align 1, !tbaa !16
  %63 = zext i8 %62 to i32
  %64 = getelementptr inbounds %struct.psa_its_file_header_t, ptr %7, i32 0, i32 2
  %65 = getelementptr inbounds [4 x i8], ptr %64, i64 0, i64 1
  %66 = load i8, ptr %65, align 1, !tbaa !16
  %67 = zext i8 %66 to i32
  %68 = shl i32 %67, 8
  %69 = or i32 %63, %68
  %70 = getelementptr inbounds %struct.psa_its_file_header_t, ptr %7, i32 0, i32 2
  %71 = getelementptr inbounds [4 x i8], ptr %70, i64 0, i64 2
  %72 = load i8, ptr %71, align 1, !tbaa !16
  %73 = zext i8 %72 to i32
  %74 = shl i32 %73, 16
  %75 = or i32 %69, %74
  %76 = getelementptr inbounds %struct.psa_its_file_header_t, ptr %7, i32 0, i32 2
  %77 = getelementptr inbounds [4 x i8], ptr %76, i64 0, i64 3
  %78 = load i8, ptr %77, align 1, !tbaa !16
  %79 = zext i8 %78 to i32
  %80 = shl i32 %79, 24
  %81 = or i32 %75, %80
  %82 = load ptr, ptr %4, align 8, !tbaa !9
  %83 = getelementptr inbounds %struct.psa_storage_info_t, ptr %82, i32 0, i32 1
  store i32 %81, ptr %83, align 4, !tbaa !19
  br label %84

84:                                               ; preds = %35, %34, %28, %19
  %85 = load i32, ptr %8, align 4, !tbaa !11
  %86 = icmp ne i32 %85, 0
  br i1 %86, label %87, label %92

87:                                               ; preds = %84
  %88 = load ptr, ptr @its_nvs, align 8, !tbaa !9
  %89 = getelementptr inbounds %struct._nvs_drv, ptr %88, i32 0, i32 1
  %90 = load ptr, ptr %89, align 8, !tbaa !20
  %91 = load i32, ptr %8, align 4, !tbaa !11
  call void %90(i32 noundef %91)
  br label %92

92:                                               ; preds = %87, %84
  %93 = load i32, ptr %6, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 13, ptr %5) #3
  ret i32 %93
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
declare hidden void @psa_its_fill_filename(i64 noundef, ptr noundef) #0

; Function Attrs: nounwind willreturn memory(read)
declare i32 @memcmp(ptr noundef, ptr noundef, i64 noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

!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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !10, i64 0}
!14 = !{!"_nvs_drv", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48}
!15 = !{!14, !10, i64 24}
!16 = !{!7, !7, i64 0}
!17 = !{!18, !12, i64 0}
!18 = !{!"psa_storage_info_t", !12, i64 0, !12, i64 4}
!19 = !{!18, !12, i64 4}
!20 = !{!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"

%struct.psa_its_file_header_t = type { [8 x i8], [4 x i8], [4 x i8] }

@its_nvs = external dso_local local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [9 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 -140, 1) i32 @psa_its_get_info(i64 noundef %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #0 {
  %3 = alloca [13 x i8], align 1
  %4 = alloca %struct.psa_its_file_header_t, align 1
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 13, ptr nonnull %3) #3
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #3
  store i32 0, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #3
  store i64 16, ptr %6, align 8, !tbaa !9
  call void @psa_its_fill_filename(i64 noundef %0, ptr noundef nonnull %3)
  %7 = load ptr, ptr @its_nvs, align 8, !tbaa !11
  %8 = load ptr, ptr %7, align 8, !tbaa !13
  %9 = call i32 %8(ptr noundef nonnull %3, i32 noundef 1, ptr noundef nonnull %5) #3
  %.not = icmp eq i32 %9, 0
  br i1 %.not, label %10, label %20

10:                                               ; preds = %2
  %11 = load ptr, ptr @its_nvs, align 8, !tbaa !11
  %12 = getelementptr inbounds i8, ptr %11, i64 24
  %13 = load ptr, ptr %12, align 8, !tbaa !15
  %14 = load i32, ptr %5, align 4, !tbaa !5
  %15 = call i32 %13(i32 noundef %14, ptr noundef nonnull @.str, ptr noundef nonnull %4, ptr noundef nonnull %6) #3
  %.not7 = icmp eq i32 %15, 0
  br i1 %.not7, label %16, label %20

16:                                               ; preds = %10
  %bcmp = call i32 @bcmp(ptr noundef nonnull dereferenceable(8) %4, ptr noundef nonnull dereferenceable(8) @.str.1, i64 8)
  %.not8 = icmp eq i32 %bcmp, 0
  br i1 %.not8, label %17, label %20

17:                                               ; preds = %16
  %18 = getelementptr inbounds i8, ptr %4, i64 8
  %19 = load <2 x i32>, ptr %18, align 1
  store <2 x i32> %19, ptr %1, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %16, %10, %2, %17
  %.0 = phi i32 [ 0, %17 ], [ -140, %2 ], [ -140, %10 ], [ -140, %16 ]
  %21 = load i32, ptr %5, align 4, !tbaa !5
  %.not9 = icmp eq i32 %21, 0
  br i1 %.not9, label %26, label %22

22:                                               ; preds = %20
  %23 = load ptr, ptr @its_nvs, align 8, !tbaa !11
  %24 = getelementptr inbounds i8, ptr %23, i64 8
  %25 = load ptr, ptr %24, align 8, !tbaa !16
  call void %25(i32 noundef %21) #3
  br label %26

26:                                               ; preds = %22, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 13, ptr nonnull %3) #3
  ret i32 %.0
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
declare hidden void @psa_its_fill_filename(i64 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nofree nounwind willreturn memory(argmem: read)
declare i32 @bcmp(ptr nocapture, ptr nocapture, i64) local_unnamed_addr #2

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nofree nounwind willreturn memory(argmem: read) }
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 = !{!"int", !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 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !12, i64 0}
!14 = !{!"_nvs_drv", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !12, i64 40, !12, i64 48}
!15 = !{!14, !12, i64 24}
!16 = !{!14, !12, i64 8}


; Effective O3 passes: AggressiveInstCombinePass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass