; 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"

; 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 i32 @psa_driver_wrapper_hash_compute(i32 noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @psa_verify_message_builtin(ptr noundef %0, ptr noundef %1, i64 noundef %2, i32 noundef %3, ptr noundef %4, i64 noundef %5, ptr noundef %6, i64 noundef %7) #2 {
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca i32, align 4
  %14 = alloca ptr, align 8
  %15 = alloca i64, align 8
  %16 = alloca ptr, align 8
  %17 = alloca i64, align 8
  %18 = alloca i32, align 4
  %19 = alloca i64, align 8
  %20 = alloca [32 x i8], align 16
  %21 = alloca i32, align 4
  store ptr %0, ptr %10, align 8, !tbaa !5
  store ptr %1, ptr %11, align 8, !tbaa !5
  store i64 %2, ptr %12, align 8, !tbaa !9
  store i32 %3, ptr %13, align 4, !tbaa !11
  store ptr %4, ptr %14, align 8, !tbaa !5
  store i64 %5, ptr %15, align 8, !tbaa !9
  store ptr %6, ptr %16, align 8, !tbaa !5
  store i64 %7, ptr %17, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #3
  store i32 -151, ptr %18, align 4, !tbaa !11
  %22 = load i32, ptr %13, align 4, !tbaa !11
  %23 = and i32 %22, -256
  %24 = icmp eq i32 %23, 100664064
  br i1 %24, label %47, label %25

25:                                               ; preds = %8
  %26 = load i32, ptr %13, align 4, !tbaa !11
  %27 = and i32 %26, -256
  %28 = icmp eq i32 %27, 100668160
  br i1 %28, label %47, label %29

29:                                               ; preds = %25
  %30 = load i32, ptr %13, align 4, !tbaa !11
  %31 = and i32 %30, -256
  %32 = icmp eq i32 %31, 100663808
  br i1 %32, label %47, label %33

33:                                               ; preds = %29
  %34 = load i32, ptr %13, align 4, !tbaa !11
  %35 = and i32 %34, -256
  %36 = and i32 %35, -257
  %37 = icmp eq i32 %36, 100664832
  br i1 %37, label %47, label %38

38:                                               ; preds = %33
  %39 = load i32, ptr %13, align 4, !tbaa !11
  %40 = and i32 %39, -256
  %41 = icmp eq i32 %40, 100665600
  br i1 %41, label %47, label %42

42:                                               ; preds = %38
  %43 = load i32, ptr %13, align 4, !tbaa !11
  %44 = and i32 %43, -256
  %45 = and i32 %44, -257
  %46 = icmp eq i32 %45, 100664320
  br i1 %46, label %47, label %103

47:                                               ; preds = %42, %38, %33, %29, %25, %8
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr %20) #3
  %48 = load i32, ptr %13, align 4, !tbaa !11
  %49 = and i32 %48, -256
  %50 = icmp eq i32 %49, 100664064
  br i1 %50, label %73, label %51

51:                                               ; preds = %47
  %52 = load i32, ptr %13, align 4, !tbaa !11
  %53 = and i32 %52, -256
  %54 = icmp eq i32 %53, 100668160
  br i1 %54, label %73, label %55

55:                                               ; preds = %51
  %56 = load i32, ptr %13, align 4, !tbaa !11
  %57 = and i32 %56, -256
  %58 = icmp eq i32 %57, 100663808
  br i1 %58, label %73, label %59

59:                                               ; preds = %55
  %60 = load i32, ptr %13, align 4, !tbaa !11
  %61 = and i32 %60, -256
  %62 = and i32 %61, -257
  %63 = icmp eq i32 %62, 100664832
  br i1 %63, label %73, label %64

64:                                               ; preds = %59
  %65 = load i32, ptr %13, align 4, !tbaa !11
  %66 = and i32 %65, -256
  %67 = icmp eq i32 %66, 100665600
  br i1 %67, label %73, label %68

68:                                               ; preds = %64
  %69 = load i32, ptr %13, align 4, !tbaa !11
  %70 = and i32 %69, -256
  %71 = and i32 %70, -257
  %72 = icmp eq i32 %71, 100664320
  br i1 %72, label %73, label %81

73:                                               ; preds = %68, %64, %59, %55, %51, %47
  %74 = load i32, ptr %13, align 4, !tbaa !11
  %75 = and i32 %74, 255
  %76 = icmp ne i32 %75, 0
  br i1 %76, label %77, label %81

77:                                               ; preds = %73
  %78 = load i32, ptr %13, align 4, !tbaa !11
  %79 = and i32 %78, 255
  %80 = or i32 %79, 33554432
  br label %82

81:                                               ; preds = %73, %68
  br label %82

82:                                               ; preds = %81, %77
  %83 = phi i32 [ %80, %77 ], [ 0, %81 ]
  %84 = load ptr, ptr %14, align 8, !tbaa !5
  %85 = load i64, ptr %15, align 8, !tbaa !9
  %86 = getelementptr inbounds [32 x i8], ptr %20, i64 0, i64 0
  %87 = call i32 @psa_driver_wrapper_hash_compute(i32 noundef %83, ptr noundef %84, i64 noundef %85, ptr noundef %86, i64 noundef 32, ptr noundef %19)
  store i32 %87, ptr %18, align 4, !tbaa !11
  %88 = load i32, ptr %18, align 4, !tbaa !11
  %89 = icmp ne i32 %88, 0
  br i1 %89, label %90, label %92

90:                                               ; preds = %82
  %91 = load i32, ptr %18, align 4, !tbaa !11
  store i32 %91, ptr %9, align 4
  store i32 1, ptr %21, align 4
  br label %102

92:                                               ; preds = %82
  %93 = load ptr, ptr %10, align 8, !tbaa !5
  %94 = load ptr, ptr %11, align 8, !tbaa !5
  %95 = load i64, ptr %12, align 8, !tbaa !9
  %96 = load i32, ptr %13, align 4, !tbaa !11
  %97 = getelementptr inbounds [32 x i8], ptr %20, i64 0, i64 0
  %98 = load i64, ptr %19, align 8, !tbaa !9
  %99 = load ptr, ptr %16, align 8, !tbaa !5
  %100 = load i64, ptr %17, align 8, !tbaa !9
  %101 = call i32 @psa_driver_wrapper_verify_hash(ptr noundef %93, ptr noundef %94, i64 noundef %95, i32 noundef %96, ptr noundef %97, i64 noundef %98, ptr noundef %99, i64 noundef %100)
  store i32 %101, ptr %9, align 4
  store i32 1, ptr %21, align 4
  br label %102

102:                                              ; preds = %92, %90
  call void @llvm.lifetime.end.p0(i64 32, ptr %20) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #3
  br label %104

103:                                              ; preds = %42
  store i32 -134, ptr %9, align 4
  store i32 1, ptr %21, align 4
  br label %104

104:                                              ; preds = %103, %102
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #3
  %105 = load i32, ptr %9, align 4
  ret i32 %105
}

declare i32 @psa_driver_wrapper_verify_hash(ptr noundef, ptr noundef, i64 noundef, i32 noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef) #1

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 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}


; 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 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

declare i32 @psa_driver_wrapper_hash_compute(i32 noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @psa_verify_message_builtin(ptr noundef %0, ptr noundef %1, i64 noundef %2, i32 noundef %3, ptr noundef %4, i64 noundef %5, ptr noundef %6, i64 noundef %7) local_unnamed_addr #2 {
  %9 = alloca i64, align 8
  %10 = alloca [32 x i8], align 16
  %11 = and i32 %3, -256
  switch i32 %11, label %switch.early.test [
    i32 100668160, label %13
    i32 100664064, label %13
    i32 100663808, label %13
    i32 100665600, label %.thread38
  ]

.thread38:                                        ; preds = %8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %9) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %10) #3
  br label %15

switch.early.test:                                ; preds = %8
  %12 = and i32 %3, -512
  switch i32 %12, label %25 [
    i32 100664832, label %13
    i32 100664320, label %13
  ]

13:                                               ; preds = %8, %8, %8, %switch.early.test, %switch.early.test
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %9) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %10) #3
  switch i32 %11, label %switch.early.test37 [
    i32 100668160, label %15
    i32 100664064, label %15
    i32 100663808, label %15
    i32 100665600, label %15
  ]

switch.early.test37:                              ; preds = %13
  %14 = and i32 %3, -512
  switch i32 %14, label %18 [
    i32 100664832, label %15
    i32 100664320, label %15
  ]

15:                                               ; preds = %13, %13, %13, %13, %.thread38, %switch.early.test37, %switch.early.test37
  %16 = and i32 %3, 255
  %.not = icmp eq i32 %16, 0
  %17 = or disjoint i32 %16, 33554432
  %spec.select = select i1 %.not, i32 0, i32 %17
  br label %18

18:                                               ; preds = %15, %switch.early.test37
  %19 = phi i32 [ 0, %switch.early.test37 ], [ %spec.select, %15 ]
  %20 = call i32 @psa_driver_wrapper_hash_compute(i32 noundef %19, ptr noundef %4, i64 noundef %5, ptr noundef nonnull %10, i64 noundef 32, ptr noundef nonnull %9) #3
  %.not29 = icmp eq i32 %20, 0
  br i1 %.not29, label %21, label %24

21:                                               ; preds = %18
  %22 = load i64, ptr %9, align 8, !tbaa !5
  %23 = call i32 @psa_driver_wrapper_verify_hash(ptr noundef %0, ptr noundef %1, i64 noundef %2, i32 noundef %3, ptr noundef nonnull %10, i64 noundef %22, ptr noundef %6, i64 noundef %7) #3
  br label %24

24:                                               ; preds = %18, %21
  %.0 = phi i32 [ %23, %21 ], [ %20, %18 ]
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %9) #3
  br label %25

25:                                               ; preds = %switch.early.test, %24
  %.1 = phi i32 [ %.0, %24 ], [ -134, %switch.early.test ]
  ret i32 %.1
}

declare i32 @psa_driver_wrapper_verify_hash(ptr noundef, ptr noundef, i64 noundef, i32 noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

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


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