; 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_sign_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, ptr noundef %8) #2 {
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  %14 = alloca i32, align 4
  %15 = alloca ptr, align 8
  %16 = alloca i64, align 8
  %17 = alloca ptr, align 8
  %18 = alloca i64, align 8
  %19 = alloca ptr, align 8
  %20 = alloca i32, align 4
  %21 = alloca i64, align 8
  %22 = alloca [32 x i8], align 16
  %23 = alloca i32, align 4
  store ptr %0, ptr %11, align 8, !tbaa !5
  store ptr %1, ptr %12, align 8, !tbaa !5
  store i64 %2, ptr %13, align 8, !tbaa !9
  store i32 %3, ptr %14, align 4, !tbaa !11
  store ptr %4, ptr %15, align 8, !tbaa !5
  store i64 %5, ptr %16, align 8, !tbaa !9
  store ptr %6, ptr %17, align 8, !tbaa !5
  store i64 %7, ptr %18, align 8, !tbaa !9
  store ptr %8, ptr %19, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #3
  store i32 -151, ptr %20, align 4, !tbaa !11
  %24 = load i32, ptr %14, align 4, !tbaa !11
  %25 = and i32 %24, -256
  %26 = icmp eq i32 %25, 100664064
  br i1 %26, label %49, label %27

27:                                               ; preds = %9
  %28 = load i32, ptr %14, align 4, !tbaa !11
  %29 = and i32 %28, -256
  %30 = icmp eq i32 %29, 100668160
  br i1 %30, label %49, label %31

31:                                               ; preds = %27
  %32 = load i32, ptr %14, align 4, !tbaa !11
  %33 = and i32 %32, -256
  %34 = icmp eq i32 %33, 100663808
  br i1 %34, label %49, label %35

35:                                               ; preds = %31
  %36 = load i32, ptr %14, align 4, !tbaa !11
  %37 = and i32 %36, -256
  %38 = and i32 %37, -257
  %39 = icmp eq i32 %38, 100664832
  br i1 %39, label %49, label %40

40:                                               ; preds = %35
  %41 = load i32, ptr %14, align 4, !tbaa !11
  %42 = and i32 %41, -256
  %43 = icmp eq i32 %42, 100665600
  br i1 %43, label %49, label %44

44:                                               ; preds = %40
  %45 = load i32, ptr %14, align 4, !tbaa !11
  %46 = and i32 %45, -256
  %47 = and i32 %46, -257
  %48 = icmp eq i32 %47, 100664320
  br i1 %48, label %49, label %106

49:                                               ; preds = %44, %40, %35, %31, %27, %9
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr %22) #3
  %50 = load i32, ptr %14, align 4, !tbaa !11
  %51 = and i32 %50, -256
  %52 = icmp eq i32 %51, 100664064
  br i1 %52, label %75, label %53

53:                                               ; preds = %49
  %54 = load i32, ptr %14, align 4, !tbaa !11
  %55 = and i32 %54, -256
  %56 = icmp eq i32 %55, 100668160
  br i1 %56, label %75, label %57

57:                                               ; preds = %53
  %58 = load i32, ptr %14, align 4, !tbaa !11
  %59 = and i32 %58, -256
  %60 = icmp eq i32 %59, 100663808
  br i1 %60, label %75, label %61

61:                                               ; preds = %57
  %62 = load i32, ptr %14, align 4, !tbaa !11
  %63 = and i32 %62, -256
  %64 = and i32 %63, -257
  %65 = icmp eq i32 %64, 100664832
  br i1 %65, label %75, label %66

66:                                               ; preds = %61
  %67 = load i32, ptr %14, align 4, !tbaa !11
  %68 = and i32 %67, -256
  %69 = icmp eq i32 %68, 100665600
  br i1 %69, label %75, label %70

70:                                               ; preds = %66
  %71 = load i32, ptr %14, align 4, !tbaa !11
  %72 = and i32 %71, -256
  %73 = and i32 %72, -257
  %74 = icmp eq i32 %73, 100664320
  br i1 %74, label %75, label %83

75:                                               ; preds = %70, %66, %61, %57, %53, %49
  %76 = load i32, ptr %14, align 4, !tbaa !11
  %77 = and i32 %76, 255
  %78 = icmp ne i32 %77, 0
  br i1 %78, label %79, label %83

79:                                               ; preds = %75
  %80 = load i32, ptr %14, align 4, !tbaa !11
  %81 = and i32 %80, 255
  %82 = or i32 %81, 33554432
  br label %84

83:                                               ; preds = %75, %70
  br label %84

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

92:                                               ; preds = %84
  %93 = load i32, ptr %20, align 4, !tbaa !11
  store i32 %93, ptr %10, align 4
  store i32 1, ptr %23, align 4
  br label %105

94:                                               ; preds = %84
  %95 = load ptr, ptr %11, align 8, !tbaa !5
  %96 = load ptr, ptr %12, align 8, !tbaa !5
  %97 = load i64, ptr %13, align 8, !tbaa !9
  %98 = load i32, ptr %14, align 4, !tbaa !11
  %99 = getelementptr inbounds [32 x i8], ptr %22, i64 0, i64 0
  %100 = load i64, ptr %21, align 8, !tbaa !9
  %101 = load ptr, ptr %17, align 8, !tbaa !5
  %102 = load i64, ptr %18, align 8, !tbaa !9
  %103 = load ptr, ptr %19, align 8, !tbaa !5
  %104 = call i32 @psa_driver_wrapper_sign_hash(ptr noundef %95, ptr noundef %96, i64 noundef %97, i32 noundef %98, ptr noundef %99, i64 noundef %100, ptr noundef %101, i64 noundef %102, ptr noundef %103)
  store i32 %104, ptr %10, align 4
  store i32 1, ptr %23, align 4
  br label %105

105:                                              ; preds = %94, %92
  call void @llvm.lifetime.end.p0(i64 32, ptr %22) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #3
  br label %107

106:                                              ; preds = %44
  store i32 -134, ptr %10, align 4
  store i32 1, ptr %23, align 4
  br label %107

107:                                              ; preds = %106, %105
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #3
  %108 = load i32, ptr %10, align 4
  ret i32 %108
}

declare i32 @psa_driver_wrapper_sign_hash(ptr noundef, ptr noundef, i64 noundef, i32 noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr 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_sign_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, ptr noundef %8) local_unnamed_addr #2 {
  %10 = alloca i64, align 8
  %11 = alloca [32 x i8], align 16
  %12 = and i32 %3, -256
  switch i32 %12, label %switch.early.test [
    i32 100668160, label %14
    i32 100664064, label %14
    i32 100663808, label %14
    i32 100665600, label %.thread39
  ]

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

switch.early.test:                                ; preds = %9
  %13 = and i32 %3, -512
  switch i32 %13, label %26 [
    i32 100664832, label %14
    i32 100664320, label %14
  ]

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

switch.early.test38:                              ; preds = %14
  %15 = and i32 %3, -512
  switch i32 %15, label %19 [
    i32 100664832, label %16
    i32 100664320, label %16
  ]

16:                                               ; preds = %14, %14, %14, %14, %.thread39, %switch.early.test38, %switch.early.test38
  %17 = and i32 %3, 255
  %.not = icmp eq i32 %17, 0
  %18 = or disjoint i32 %17, 33554432
  %spec.select = select i1 %.not, i32 0, i32 %18
  br label %19

19:                                               ; preds = %16, %switch.early.test38
  %20 = phi i32 [ 0, %switch.early.test38 ], [ %spec.select, %16 ]
  %21 = call i32 @psa_driver_wrapper_hash_compute(i32 noundef %20, ptr noundef %4, i64 noundef %5, ptr noundef nonnull %11, i64 noundef 32, ptr noundef nonnull %10) #3
  %.not30 = icmp eq i32 %21, 0
  br i1 %.not30, label %22, label %25

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

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

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

declare i32 @psa_driver_wrapper_sign_hash(ptr noundef, ptr noundef, i64 noundef, i32 noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr 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