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

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

@.str = external hidden unnamed_addr constant [76 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @ossl_ml_dsa_set_prekey(ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3, i64 noundef %4, ptr noundef %5, i64 noundef %6) #0 {
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i64, align 8
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  store ptr %0, ptr %9, align 8, !tbaa !5
  store i32 %1, ptr %10, align 4, !tbaa !9
  store i32 %2, ptr %11, align 4, !tbaa !9
  store ptr %3, ptr %12, align 8, !tbaa !5
  store i64 %4, ptr %13, align 8, !tbaa !11
  store ptr %5, ptr %14, align 8, !tbaa !5
  store i64 %6, ptr %15, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  store i32 0, ptr %16, align 4, !tbaa !9
  %18 = load ptr, ptr %9, align 8, !tbaa !5
  %19 = icmp eq ptr %18, null
  br i1 %19, label %52, label %20

20:                                               ; preds = %7
  %21 = load ptr, ptr %9, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.ml_dsa_key_st, ptr %21, i32 0, i32 7
  %23 = load ptr, ptr %22, align 8, !tbaa !13
  %24 = icmp ne ptr %23, null
  br i1 %24, label %52, label %25

25:                                               ; preds = %20
  %26 = load ptr, ptr %9, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.ml_dsa_key_st, ptr %26, i32 0, i32 8
  %28 = load ptr, ptr %27, align 8, !tbaa !16
  %29 = icmp ne ptr %28, null
  br i1 %29, label %52, label %30

30:                                               ; preds = %25
  %31 = load ptr, ptr %14, align 8, !tbaa !5
  %32 = icmp ne ptr %31, null
  br i1 %32, label %33, label %41

33:                                               ; preds = %30
  %34 = load i64, ptr %15, align 8, !tbaa !11
  %35 = load ptr, ptr %9, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.ml_dsa_key_st, ptr %35, i32 0, i32 1
  %37 = load ptr, ptr %36, align 8, !tbaa !17
  %38 = getelementptr inbounds %struct.ml_dsa_params_st, ptr %37, i32 0, i32 12
  %39 = load i64, ptr %38, align 8, !tbaa !18
  %40 = icmp ne i64 %34, %39
  br i1 %40, label %52, label %41

41:                                               ; preds = %33, %30
  %42 = load ptr, ptr %12, align 8, !tbaa !5
  %43 = icmp ne ptr %42, null
  br i1 %43, label %44, label %47

44:                                               ; preds = %41
  %45 = load i64, ptr %13, align 8, !tbaa !11
  %46 = icmp ne i64 %45, 32
  br i1 %46, label %52, label %47

47:                                               ; preds = %44, %41
  %48 = load ptr, ptr %9, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.ml_dsa_key_st, ptr %48, i32 0, i32 9
  %50 = load ptr, ptr %49, align 8, !tbaa !20
  %51 = icmp ne ptr %50, null
  br i1 %51, label %52, label %53

52:                                               ; preds = %47, %44, %33, %25, %20, %7
  store i32 0, ptr %8, align 4
  store i32 1, ptr %17, align 4
  br label %103

53:                                               ; preds = %47
  %54 = load ptr, ptr %14, align 8, !tbaa !5
  %55 = icmp ne ptr %54, null
  br i1 %55, label %56, label %64

56:                                               ; preds = %53
  %57 = load ptr, ptr %14, align 8, !tbaa !5
  %58 = load i64, ptr %15, align 8, !tbaa !11
  %59 = call ptr @CRYPTO_memdup(ptr noundef %57, i64 noundef %58, ptr noundef @.str, i32 noundef 52)
  %60 = load ptr, ptr %9, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.ml_dsa_key_st, ptr %60, i32 0, i32 8
  store ptr %59, ptr %61, align 8, !tbaa !16
  %62 = icmp eq ptr %59, null
  br i1 %62, label %63, label %64

63:                                               ; preds = %56
  br label %87

64:                                               ; preds = %56, %53
  %65 = load ptr, ptr %12, align 8, !tbaa !5
  %66 = icmp ne ptr %65, null
  br i1 %66, label %67, label %75

67:                                               ; preds = %64
  %68 = load ptr, ptr %12, align 8, !tbaa !5
  %69 = load i64, ptr %13, align 8, !tbaa !11
  %70 = call ptr @CRYPTO_memdup(ptr noundef %68, i64 noundef %69, ptr noundef @.str, i32 noundef 55)
  %71 = load ptr, ptr %9, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.ml_dsa_key_st, ptr %71, i32 0, i32 9
  store ptr %70, ptr %72, align 8, !tbaa !20
  %73 = icmp eq ptr %70, null
  br i1 %73, label %74, label %75

74:                                               ; preds = %67
  br label %87

75:                                               ; preds = %67, %64
  %76 = load i32, ptr %10, align 4, !tbaa !9
  %77 = load ptr, ptr %9, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.ml_dsa_key_st, ptr %77, i32 0, i32 10
  %79 = load i32, ptr %78, align 8, !tbaa !21
  %80 = or i32 %79, %76
  store i32 %80, ptr %78, align 8, !tbaa !21
  %81 = load i32, ptr %11, align 4, !tbaa !9
  %82 = xor i32 %81, -1
  %83 = load ptr, ptr %9, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.ml_dsa_key_st, ptr %83, i32 0, i32 10
  %85 = load i32, ptr %84, align 8, !tbaa !21
  %86 = and i32 %85, %82
  store i32 %86, ptr %84, align 8, !tbaa !21
  store i32 1, ptr %16, align 4, !tbaa !9
  br label %87

87:                                               ; preds = %75, %74, %63
  %88 = load i32, ptr %16, align 4, !tbaa !9
  %89 = icmp ne i32 %88, 0
  br i1 %89, label %101, label %90

90:                                               ; preds = %87
  %91 = load ptr, ptr %9, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.ml_dsa_key_st, ptr %91, i32 0, i32 8
  %93 = load ptr, ptr %92, align 8, !tbaa !16
  call void @CRYPTO_free(ptr noundef %93, ptr noundef @.str, i32 noundef 63)
  %94 = load ptr, ptr %9, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.ml_dsa_key_st, ptr %94, i32 0, i32 9
  %96 = load ptr, ptr %95, align 8, !tbaa !20
  call void @CRYPTO_free(ptr noundef %96, ptr noundef @.str, i32 noundef 64)
  %97 = load ptr, ptr %9, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.ml_dsa_key_st, ptr %97, i32 0, i32 9
  store ptr null, ptr %98, align 8, !tbaa !20
  %99 = load ptr, ptr %9, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.ml_dsa_key_st, ptr %99, i32 0, i32 8
  store ptr null, ptr %100, align 8, !tbaa !16
  br label %101

101:                                              ; preds = %90, %87
  %102 = load i32, ptr %16, align 4, !tbaa !9
  store i32 %102, ptr %8, align 4
  store i32 1, ptr %17, align 4
  br label %103

103:                                              ; preds = %101, %52
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  %104 = load i32, ptr %8, align 4
  ret i32 %104
}

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

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

declare void @CRYPTO_free(ptr noundef, ptr noundef, i32 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 = { "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 160}
!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 = !{!14, !6, i64 168}
!17 = !{!14, !6, i64 8}
!18 = !{!19, !12, i64 64}
!19 = !{!"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}
!20 = !{!14, !6, i64 176}
!21 = !{!14, !10, i64 184}


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

@.str = external hidden unnamed_addr constant [76 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @ossl_ml_dsa_set_prekey(ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3, i64 noundef %4, ptr noundef %5, i64 noundef %6) local_unnamed_addr #0 {
  %8 = icmp eq ptr %0, null
  br i1 %8, label %44, label %9

9:                                                ; preds = %7
  %10 = getelementptr inbounds i8, ptr %0, i64 160
  %11 = load ptr, ptr %10, align 8, !tbaa !5
  %.not = icmp eq ptr %11, null
  br i1 %.not, label %12, label %44

12:                                               ; preds = %9
  %13 = getelementptr inbounds i8, ptr %0, i64 168
  %14 = load ptr, ptr %13, align 8, !tbaa !13
  %.not32 = icmp eq ptr %14, null
  br i1 %.not32, label %15, label %44

15:                                               ; preds = %12
  %.not33 = icmp eq ptr %5, null
  br i1 %.not33, label %21, label %16

16:                                               ; preds = %15
  %17 = getelementptr inbounds i8, ptr %0, i64 8
  %18 = load ptr, ptr %17, align 8, !tbaa !14
  %19 = getelementptr inbounds i8, ptr %18, i64 64
  %20 = load i64, ptr %19, align 8, !tbaa !15
  %.not34 = icmp eq i64 %20, %6
  br i1 %.not34, label %21, label %44

21:                                               ; preds = %16, %15
  %22 = icmp ne ptr %3, null
  %23 = icmp ne i64 %4, 32
  %or.cond = and i1 %22, %23
  br i1 %or.cond, label %44, label %24

24:                                               ; preds = %21
  %25 = getelementptr inbounds i8, ptr %0, i64 176
  %26 = load ptr, ptr %25, align 8, !tbaa !17
  %.not35 = icmp eq ptr %26, null
  br i1 %.not35, label %27, label %44

27:                                               ; preds = %24
  br i1 %.not33, label %31, label %28

28:                                               ; preds = %27
  %29 = tail call ptr @CRYPTO_memdup(ptr noundef nonnull %5, i64 noundef %6, ptr noundef nonnull @.str, i32 noundef 52) #3
  store ptr %29, ptr %13, align 8, !tbaa !13
  %30 = icmp eq ptr %29, null
  br i1 %30, label %41, label %31

31:                                               ; preds = %28, %27
  br i1 %22, label %32, label %35

32:                                               ; preds = %31
  %33 = tail call ptr @CRYPTO_memdup(ptr noundef nonnull %3, i64 noundef %4, ptr noundef nonnull @.str, i32 noundef 55) #3
  store ptr %33, ptr %25, align 8, !tbaa !17
  %34 = icmp eq ptr %33, null
  br i1 %34, label %._crit_edge, label %35

._crit_edge:                                      ; preds = %32
  %.pre = load ptr, ptr %13, align 8, !tbaa !13
  br label %41

35:                                               ; preds = %31, %32
  %36 = getelementptr inbounds i8, ptr %0, i64 184
  %37 = load i32, ptr %36, align 8, !tbaa !18
  %38 = or i32 %37, %1
  %39 = xor i32 %2, -1
  %40 = and i32 %38, %39
  store i32 %40, ptr %36, align 8, !tbaa !18
  br label %44

41:                                               ; preds = %._crit_edge, %28
  %42 = phi ptr [ %.pre, %._crit_edge ], [ null, %28 ]
  tail call void @CRYPTO_free(ptr noundef %42, ptr noundef nonnull @.str, i32 noundef 63) #3
  %43 = load ptr, ptr %25, align 8, !tbaa !17
  tail call void @CRYPTO_free(ptr noundef %43, ptr noundef nonnull @.str, i32 noundef 64) #3
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %13, i8 0, i64 16, i1 false)
  br label %44

44:                                               ; preds = %35, %41, %7, %9, %12, %16, %24, %21
  %.028 = phi i32 [ 0, %21 ], [ 0, %24 ], [ 0, %16 ], [ 0, %12 ], [ 0, %9 ], [ 0, %7 ], [ 0, %41 ], [ 1, %35 ]
  ret i32 %.028
}

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

declare void @CRYPTO_free(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 160}
!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 = !{!6, !7, i64 168}
!14 = !{!6, !7, i64 8}
!15 = !{!16, !12, i64 64}
!16 = !{!"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}
!17 = !{!6, !7, i64 176}
!18 = !{!6, !10, i64 184}


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