; LLVM IR from openssl/openssl :: crypto/ml_dsa (ml_dsa_sign)

; 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.ml_dsa_key_st = type { ptr, ptr, ptr, ptr, [32 x i8], [64 x i8], [32 x i8], ptr, ptr, ptr, i32, %struct.vector_st, %struct.vector_st, %struct.vector_st, %struct.vector_st }
%struct.vector_st = type { ptr, i64 }
%struct.ml_dsa_params_st = type { ptr, i32, i32, i32, i32, i32, i64, i64, i32, i32, i32, i32, i64, i64, i64 }

; Function Attrs: nounwind uwtable
declare dso_local ptr @ossl_ml_dsa_mu_init(ptr noundef, i32 noundef, ptr noundef, i64 noundef) #0

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

declare void @EVP_MD_CTX_free(ptr noundef) #2

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @ossl_ml_dsa_mu_update(ptr noundef, ptr noundef, i64 noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @ossl_ml_dsa_mu_finalize(ptr noundef, ptr noundef, i64 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @ossl_ml_dsa_sign(ptr noundef %0, i32 noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4, i64 noundef %5, ptr noundef %6, i64 noundef %7, i32 noundef %8, ptr noundef %9, ptr noundef %10, i64 noundef %11) #0 {
  %13 = alloca i32, align 4
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  %16 = alloca ptr, align 8
  %17 = alloca i64, align 8
  %18 = alloca ptr, align 8
  %19 = alloca i64, align 8
  %20 = alloca ptr, align 8
  %21 = alloca i64, align 8
  %22 = alloca i32, align 4
  %23 = alloca ptr, align 8
  %24 = alloca ptr, align 8
  %25 = alloca i64, align 8
  %26 = alloca ptr, align 8
  %27 = alloca [64 x i8], align 16
  %28 = alloca ptr, align 8
  %29 = alloca i64, align 8
  %30 = alloca i32, align 4
  %31 = alloca i32, align 4
  store ptr %0, ptr %14, align 8, !tbaa !5
  store i32 %1, ptr %15, align 4, !tbaa !9
  store ptr %2, ptr %16, align 8, !tbaa !5
  store i64 %3, ptr %17, align 8, !tbaa !11
  store ptr %4, ptr %18, align 8, !tbaa !5
  store i64 %5, ptr %19, align 8, !tbaa !11
  store ptr %6, ptr %20, align 8, !tbaa !5
  store i64 %7, ptr %21, align 8, !tbaa !11
  store i32 %8, ptr %22, align 4, !tbaa !9
  store ptr %9, ptr %23, align 8, !tbaa !5
  store ptr %10, ptr %24, align 8, !tbaa !5
  store i64 %11, ptr %25, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %26) #3
  store ptr null, ptr %26, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 64, ptr %27) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %28) #3
  %32 = getelementptr inbounds [64 x i8], ptr %27, i64 0, i64 0
  store ptr %32, ptr %28, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %29) #3
  store i64 64, ptr %29, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %30) #3
  store i32 0, ptr %30, align 4, !tbaa !9
  %33 = load ptr, ptr %14, align 8, !tbaa !5
  %34 = call ptr @ossl_ml_dsa_key_get_priv(ptr noundef %33)
  %35 = icmp eq ptr %34, null
  br i1 %35, label %36, label %37

36:                                               ; preds = %12
  store i32 0, ptr %13, align 4
  store i32 1, ptr %31, align 4
  br label %105

37:                                               ; preds = %12
  %38 = load ptr, ptr %24, align 8, !tbaa !5
  %39 = icmp ne ptr %38, null
  br i1 %39, label %40, label %47

40:                                               ; preds = %37
  %41 = load ptr, ptr %14, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.ml_dsa_key_st, ptr %41, i32 0, i32 1
  %43 = load ptr, ptr %42, align 8, !tbaa !13
  %44 = getelementptr inbounds %struct.ml_dsa_params_st, ptr %43, i32 0, i32 14
  %45 = load i64, ptr %44, align 8, !tbaa !16
  %46 = load ptr, ptr %24, align 8, !tbaa !5
  store i64 %45, ptr %46, align 8, !tbaa !11
  br label %47

47:                                               ; preds = %40, %37
  %48 = load ptr, ptr %23, align 8, !tbaa !5
  %49 = icmp eq ptr %48, null
  br i1 %49, label %50, label %55

50:                                               ; preds = %47
  %51 = load ptr, ptr %24, align 8, !tbaa !5
  %52 = icmp ne ptr %51, null
  %53 = zext i1 %52 to i64
  %54 = select i1 %52, i32 1, i32 0
  store i32 %54, ptr %13, align 4
  store i32 1, ptr %31, align 4
  br label %105

55:                                               ; preds = %47
  %56 = load i64, ptr %25, align 8, !tbaa !11
  %57 = load ptr, ptr %14, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.ml_dsa_key_st, ptr %57, i32 0, i32 1
  %59 = load ptr, ptr %58, align 8, !tbaa !13
  %60 = getelementptr inbounds %struct.ml_dsa_params_st, ptr %59, i32 0, i32 14
  %61 = load i64, ptr %60, align 8, !tbaa !16
  %62 = icmp ult i64 %56, %61
  br i1 %62, label %63, label %64

63:                                               ; preds = %55
  store i32 0, ptr %13, align 4
  store i32 1, ptr %31, align 4
  br label %105

64:                                               ; preds = %55
  %65 = load i32, ptr %15, align 4, !tbaa !9
  %66 = icmp ne i32 %65, 0
  br i1 %66, label %67, label %70

67:                                               ; preds = %64
  %68 = load ptr, ptr %16, align 8, !tbaa !5
  store ptr %68, ptr %28, align 8, !tbaa !5
  %69 = load i64, ptr %17, align 8, !tbaa !11
  store i64 %69, ptr %29, align 8, !tbaa !11
  br label %94

70:                                               ; preds = %64
  %71 = load ptr, ptr %14, align 8, !tbaa !5
  %72 = load i32, ptr %22, align 4, !tbaa !9
  %73 = load ptr, ptr %18, align 8, !tbaa !5
  %74 = load i64, ptr %19, align 8, !tbaa !11
  %75 = call ptr @ossl_ml_dsa_mu_init(ptr noundef %71, i32 noundef %72, ptr noundef %73, i64 noundef %74)
  store ptr %75, ptr %26, align 8, !tbaa !5
  %76 = load ptr, ptr %26, align 8, !tbaa !5
  %77 = icmp eq ptr %76, null
  br i1 %77, label %78, label %79

78:                                               ; preds = %70
  store i32 0, ptr %13, align 4
  store i32 1, ptr %31, align 4
  br label %105

79:                                               ; preds = %70
  %80 = load ptr, ptr %26, align 8, !tbaa !5
  %81 = load ptr, ptr %16, align 8, !tbaa !5
  %82 = load i64, ptr %17, align 8, !tbaa !11
  %83 = call i32 @ossl_ml_dsa_mu_update(ptr noundef %80, ptr noundef %81, i64 noundef %82)
  %84 = icmp ne i32 %83, 0
  br i1 %84, label %86, label %85

85:                                               ; preds = %79
  br label %102

86:                                               ; preds = %79
  %87 = load ptr, ptr %26, align 8, !tbaa !5
  %88 = getelementptr inbounds [64 x i8], ptr %27, i64 0, i64 0
  %89 = load i64, ptr %29, align 8, !tbaa !11
  %90 = call i32 @ossl_ml_dsa_mu_finalize(ptr noundef %87, ptr noundef %88, i64 noundef %89)
  %91 = icmp ne i32 %90, 0
  br i1 %91, label %93, label %92

92:                                               ; preds = %86
  br label %102

93:                                               ; preds = %86
  br label %94

94:                                               ; preds = %93, %67
  %95 = load ptr, ptr %14, align 8, !tbaa !5
  %96 = load ptr, ptr %28, align 8, !tbaa !5
  %97 = load i64, ptr %29, align 8, !tbaa !11
  %98 = load ptr, ptr %20, align 8, !tbaa !5
  %99 = load i64, ptr %21, align 8, !tbaa !11
  %100 = load ptr, ptr %23, align 8, !tbaa !5
  %101 = call i32 @ml_dsa_sign_internal(ptr noundef %95, ptr noundef %96, i64 noundef %97, ptr noundef %98, i64 noundef %99, ptr noundef %100)
  store i32 %101, ptr %30, align 4, !tbaa !9
  br label %102

102:                                              ; preds = %94, %92, %85
  %103 = load ptr, ptr %26, align 8, !tbaa !5
  call void @EVP_MD_CTX_free(ptr noundef %103)
  %104 = load i32, ptr %30, align 4, !tbaa !9
  store i32 %104, ptr %13, align 4
  store i32 1, ptr %31, align 4
  br label %105

105:                                              ; preds = %102, %78, %63, %50, %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %30) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %29) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %28) #3
  call void @llvm.lifetime.end.p0(i64 64, ptr %27) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %26) #3
  %106 = load i32, ptr %13, align 4
  ret i32 %106
}

declare ptr @ossl_ml_dsa_key_get_priv(ptr noundef) #2

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

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 = { "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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !6, i64 8}
!14 = !{!"ml_dsa_key_st", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !7, i64 32, !7, i64 64, !7, i64 128, !6, i64 160, !6, i64 168, !6, i64 176, !10, i64 184, !15, i64 192, !15, i64 208, !15, i64 224, !15, i64 240}
!15 = !{!"vector_st", !6, i64 0, !12, i64 8}
!16 = !{!17, !12, i64 80}
!17 = !{!"ml_dsa_params_st", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !12, i64 32, !12, i64 40, !10, i64 48, !10, i64 52, !10, i64 56, !10, i64 60, !12, i64 64, !12, i64 72, !12, i64 80}


; 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: nounwind uwtable
declare dso_local ptr @ossl_ml_dsa_mu_init(ptr noundef, i32 noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

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

declare void @EVP_MD_CTX_free(ptr noundef) local_unnamed_addr #2

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @ossl_ml_dsa_mu_update(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @ossl_ml_dsa_mu_finalize(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @ossl_ml_dsa_sign(ptr noundef %0, i32 noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4, i64 noundef %5, ptr noundef %6, i64 noundef %7, i32 noundef %8, ptr noundef %9, ptr noundef writeonly %10, i64 noundef %11) local_unnamed_addr #0 {
  %13 = alloca [64 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %13) #3
  %14 = tail call ptr @ossl_ml_dsa_key_get_priv(ptr noundef %0) #3
  %15 = icmp eq ptr %14, null
  br i1 %15, label %43, label %16

16:                                               ; preds = %12
  %.not = icmp ne ptr %10, null
  br i1 %.not, label %17, label %22

17:                                               ; preds = %16
  %18 = getelementptr inbounds i8, ptr %0, i64 8
  %19 = load ptr, ptr %18, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %19, i64 80
  %21 = load i64, ptr %20, align 8, !tbaa !13
  store i64 %21, ptr %10, align 8, !tbaa !15
  br label %22

22:                                               ; preds = %17, %16
  %23 = icmp eq ptr %9, null
  br i1 %23, label %24, label %26

24:                                               ; preds = %22
  %25 = zext i1 %.not to i32
  br label %43

26:                                               ; preds = %22
  %27 = getelementptr inbounds i8, ptr %0, i64 8
  %28 = load ptr, ptr %27, align 8, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %28, i64 80
  %30 = load i64, ptr %29, align 8, !tbaa !13
  %31 = icmp ugt i64 %30, %11
  br i1 %31, label %43, label %32

32:                                               ; preds = %26
  %.not36 = icmp eq i32 %1, 0
  br i1 %.not36, label %33, label %40

33:                                               ; preds = %32
  %34 = tail call ptr @ossl_ml_dsa_mu_init(ptr noundef nonnull %0, i32 noundef %8, ptr noundef %4, i64 noundef %5)
  %35 = icmp eq ptr %34, null
  br i1 %35, label %43, label %36

36:                                               ; preds = %33
  %37 = tail call i32 @ossl_ml_dsa_mu_update(ptr noundef nonnull %34, ptr noundef %2, i64 noundef %3)
  %.not37 = icmp eq i32 %37, 0
  br i1 %.not37, label %42, label %38

38:                                               ; preds = %36
  %39 = call i32 @ossl_ml_dsa_mu_finalize(ptr noundef nonnull %34, ptr noundef nonnull %13, i64 noundef 64)
  %.not38 = icmp eq i32 %39, 0
  br i1 %.not38, label %42, label %40

40:                                               ; preds = %32, %38
  %.031 = phi ptr [ %34, %38 ], [ null, %32 ]
  %.030 = phi ptr [ %13, %38 ], [ %2, %32 ]
  %.029 = phi i64 [ 64, %38 ], [ %3, %32 ]
  %41 = call i32 @ml_dsa_sign_internal(ptr noundef nonnull %0, ptr noundef %.030, i64 noundef %.029, ptr noundef %6, i64 noundef %7, ptr noundef nonnull %9)
  br label %42

42:                                               ; preds = %38, %36, %40
  %.1 = phi ptr [ %.031, %40 ], [ %34, %38 ], [ %34, %36 ]
  %.0 = phi i32 [ %41, %40 ], [ 0, %38 ], [ 0, %36 ]
  call void @EVP_MD_CTX_free(ptr noundef %.1) #3
  br label %43

43:                                               ; preds = %33, %26, %12, %42, %24
  %.032 = phi i32 [ %25, %24 ], [ %.0, %42 ], [ 0, %12 ], [ 0, %26 ], [ 0, %33 ]
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %13) #3
  ret i32 %.032
}

declare ptr @ossl_ml_dsa_key_get_priv(ptr noundef) local_unnamed_addr #2

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

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 = { "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 8}
!6 = !{!"ml_dsa_key_st", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !8, i64 32, !8, i64 64, !8, i64 128, !7, i64 160, !7, i64 168, !7, i64 176, !10, i64 184, !11, i64 192, !11, i64 208, !11, i64 224, !11, i64 240}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"vector_st", !7, i64 0, !12, i64 8}
!12 = !{!"long", !8, i64 0}
!13 = !{!14, !12, i64 80}
!14 = !{!"ml_dsa_params_st", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !12, i64 32, !12, i64 40, !10, i64 48, !10, i64 52, !10, i64 56, !10, i64 60, !12, i64 64, !12, i64 72, !12, i64 80}
!15 = !{!12, !12, i64 0}


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