; 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
@__func__.ossl_ml_dsa_generate_key = external hidden unnamed_addr constant [25 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [44 x i8], align 1

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @ossl_ml_dsa_key_reset(ptr noundef) #2

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @ossl_ml_dsa_generate_key(ptr noundef %0) #2 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  store i64 32, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.ml_dsa_key_st, ptr %8, i32 0, i32 9
  %10 = load ptr, ptr %9, align 8, !tbaa !11
  %11 = icmp eq ptr %10, null
  br i1 %11, label %12, label %36

12:                                               ; preds = %1
  %13 = load i64, ptr %4, align 8, !tbaa !9
  %14 = call ptr @CRYPTO_malloc(i64 noundef %13, ptr noundef @.str, i32 noundef 464)
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.ml_dsa_key_st, ptr %15, i32 0, i32 9
  store ptr %14, ptr %16, align 8, !tbaa !11
  %17 = icmp eq ptr %14, null
  br i1 %17, label %18, label %19

18:                                               ; preds = %12
  store i32 0, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %74

19:                                               ; preds = %12
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.ml_dsa_key_st, ptr %20, i32 0, i32 0
  %22 = load ptr, ptr %21, align 8, !tbaa !15
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.ml_dsa_key_st, ptr %23, i32 0, i32 9
  %25 = load ptr, ptr %24, align 8, !tbaa !11
  %26 = load i64, ptr %4, align 8, !tbaa !9
  %27 = call i32 @RAND_priv_bytes_ex(ptr noundef %22, ptr noundef %25, i64 noundef %26, i32 noundef 0)
  %28 = icmp sle i32 %27, 0
  br i1 %28, label %29, label %35

29:                                               ; preds = %19
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.ml_dsa_key_st, ptr %30, i32 0, i32 9
  %32 = load ptr, ptr %31, align 8, !tbaa !11
  call void @CRYPTO_free(ptr noundef %32, ptr noundef @.str, i32 noundef 467)
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.ml_dsa_key_st, ptr %33, i32 0, i32 9
  store ptr null, ptr %34, align 8, !tbaa !11
  store i32 0, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %74

35:                                               ; preds = %19
  br label %36

36:                                               ; preds = %35, %1
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.ml_dsa_key_st, ptr %37, i32 0, i32 8
  %39 = load ptr, ptr %38, align 8, !tbaa !16
  store ptr %39, ptr %5, align 8, !tbaa !5
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.ml_dsa_key_st, ptr %40, i32 0, i32 8
  store ptr null, ptr %41, align 8, !tbaa !16
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = icmp eq ptr %42, null
  br i1 %43, label %44, label %47

44:                                               ; preds = %36
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = call i32 @keygen_internal(ptr noundef %45)
  store i32 %46, ptr %6, align 4, !tbaa !17
  br label %72

47:                                               ; preds = %36
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = call i32 @keygen_internal(ptr noundef %48)
  store i32 %49, ptr %6, align 4, !tbaa !17
  %50 = icmp ne i32 %49, 0
  br i1 %50, label %51, label %70

51:                                               ; preds = %47
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.ml_dsa_key_st, ptr %52, i32 0, i32 8
  %54 = load ptr, ptr %53, align 8, !tbaa !16
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.ml_dsa_key_st, ptr %56, i32 0, i32 1
  %58 = load ptr, ptr %57, align 8, !tbaa !18
  %59 = getelementptr inbounds %struct.ml_dsa_params_st, ptr %58, i32 0, i32 12
  %60 = load i64, ptr %59, align 8, !tbaa !19
  %61 = call i32 @memcmp(ptr noundef %54, ptr noundef %55, i64 noundef %60) #5
  %62 = icmp ne i32 %61, 0
  br i1 %62, label %63, label %70

63:                                               ; preds = %51
  store i32 0, ptr %6, align 4, !tbaa !17
  %64 = load ptr, ptr %3, align 8, !tbaa !5
  call void @ossl_ml_dsa_key_reset(ptr noundef %64)
  call void @ERR_new()
  call void @ERR_set_debug(ptr noundef @.str, i32 noundef 482, ptr noundef @__func__.ossl_ml_dsa_generate_key)
  %65 = load ptr, ptr %3, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.ml_dsa_key_st, ptr %65, i32 0, i32 1
  %67 = load ptr, ptr %66, align 8, !tbaa !18
  %68 = getelementptr inbounds %struct.ml_dsa_params_st, ptr %67, i32 0, i32 0
  %69 = load ptr, ptr %68, align 8, !tbaa !21
  call void (i32, i32, ptr, ...) @ERR_set_error(i32 noundef 57, i32 noundef 158, ptr noundef @.str.3, ptr noundef %69)
  br label %70

70:                                               ; preds = %63, %51, %47
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  call void @CRYPTO_free(ptr noundef %71, ptr noundef @.str, i32 noundef 486)
  br label %72

72:                                               ; preds = %70, %44
  %73 = load i32, ptr %6, align 4, !tbaa !17
  store i32 %73, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %74

74:                                               ; preds = %72, %29, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  %75 = load i32, ptr %2, align 4
  ret i32 %75
}

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

; Function Attrs: nounwind uwtable
declare hidden i32 @keygen_internal(ptr noundef) #2

declare void @ERR_new() #1

declare void @ERR_set_debug(ptr noundef, i32 noundef, ptr noundef) #1

declare void @ERR_set_error(i32 noundef, i32 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 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 #4 = { nounwind }
attributes #5 = { 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 = !{!"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, !6, i64 176}
!12 = !{!"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, !13, i64 184, !14, i64 192, !14, i64 208, !14, i64 224, !14, i64 240}
!13 = !{!"int", !7, i64 0}
!14 = !{!"vector_st", !6, i64 0, !10, i64 8}
!15 = !{!12, !6, i64 0}
!16 = !{!12, !6, i64 168}
!17 = !{!13, !13, i64 0}
!18 = !{!12, !6, i64 8}
!19 = !{!20, !10, i64 64}
!20 = !{!"ml_dsa_params_st", !6, i64 0, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20, !13, i64 24, !10, i64 32, !10, i64 40, !13, i64 48, !13, i64 52, !13, i64 56, !13, i64 60, !10, i64 64, !10, i64 72, !10, i64 80}
!21 = !{!20, !6, 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"

@.str = external hidden unnamed_addr constant [76 x i8], align 1
@__func__.ossl_ml_dsa_generate_key = external hidden unnamed_addr constant [25 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [44 x i8], align 1

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

; Function Attrs: nounwind uwtable
declare dso_local void @ossl_ml_dsa_key_reset(ptr noundef) local_unnamed_addr #1

declare ptr @CRYPTO_malloc(i64 noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @ossl_ml_dsa_generate_key(ptr noundef %0) local_unnamed_addr #1 {
  %2 = getelementptr inbounds i8, ptr %0, i64 176
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = icmp eq ptr %3, null
  br i1 %4, label %5, label %14

5:                                                ; preds = %1
  %6 = tail call ptr @CRYPTO_malloc(i64 noundef 32, ptr noundef nonnull @.str, i32 noundef 464) #3
  store ptr %6, ptr %2, align 8, !tbaa !5
  %7 = icmp eq ptr %6, null
  br i1 %7, label %30, label %8

8:                                                ; preds = %5
  %9 = load ptr, ptr %0, align 8, !tbaa !13
  %10 = tail call i32 @RAND_priv_bytes_ex(ptr noundef %9, ptr noundef nonnull %6, i64 noundef 32, i32 noundef 0) #3
  %11 = icmp slt i32 %10, 1
  br i1 %11, label %12, label %14

12:                                               ; preds = %8
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  tail call void @CRYPTO_free(ptr noundef %13, ptr noundef nonnull @.str, i32 noundef 467) #3
  store ptr null, ptr %2, align 8, !tbaa !5
  br label %30

14:                                               ; preds = %8, %1
  %15 = getelementptr inbounds i8, ptr %0, i64 168
  %16 = load ptr, ptr %15, align 8, !tbaa !14
  store ptr null, ptr %15, align 8, !tbaa !14
  %17 = icmp eq ptr %16, null
  %18 = tail call i32 @keygen_internal(ptr noundef nonnull %0)
  br i1 %17, label %30, label %19

19:                                               ; preds = %14
  %.not = icmp eq i32 %18, 0
  br i1 %.not, label %29, label %20

20:                                               ; preds = %19
  %21 = load ptr, ptr %15, align 8, !tbaa !14
  %22 = getelementptr inbounds i8, ptr %0, i64 8
  %23 = load ptr, ptr %22, align 8, !tbaa !15
  %24 = getelementptr inbounds i8, ptr %23, i64 64
  %25 = load i64, ptr %24, align 8, !tbaa !16
  %bcmp = tail call i32 @bcmp(ptr %21, ptr nonnull %16, i64 %25)
  %.not25 = icmp eq i32 %bcmp, 0
  br i1 %.not25, label %29, label %26

26:                                               ; preds = %20
  tail call void @ossl_ml_dsa_key_reset(ptr noundef nonnull %0)
  tail call void @ERR_new() #3
  tail call void @ERR_set_debug(ptr noundef nonnull @.str, i32 noundef 482, ptr noundef nonnull @__func__.ossl_ml_dsa_generate_key) #3
  %27 = load ptr, ptr %22, align 8, !tbaa !15
  %28 = load ptr, ptr %27, align 8, !tbaa !18
  tail call void (i32, i32, ptr, ...) @ERR_set_error(i32 noundef 57, i32 noundef 158, ptr noundef nonnull @.str.3, ptr noundef %28) #3
  br label %29

29:                                               ; preds = %26, %20, %19
  %.0 = phi i32 [ 0, %26 ], [ %18, %20 ], [ 0, %19 ]
  tail call void @CRYPTO_free(ptr noundef nonnull %16, ptr noundef nonnull @.str, i32 noundef 486) #3
  br label %30

30:                                               ; preds = %14, %29, %5, %12
  %.020 = phi i32 [ 0, %12 ], [ 0, %5 ], [ %.0, %29 ], [ %18, %14 ]
  ret i32 %.020
}

declare i32 @RAND_priv_bytes_ex(ptr noundef, ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i32 @keygen_internal(ptr noundef) local_unnamed_addr #1

declare void @ERR_new() local_unnamed_addr #0

declare void @ERR_set_debug(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

declare void @ERR_set_error(i32 noundef, i32 noundef, ptr noundef, ...) local_unnamed_addr #0

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

attributes #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 = { 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 #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, !7, i64 176}
!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 0}
!14 = !{!6, !7, i64 168}
!15 = !{!6, !7, i64 8}
!16 = !{!17, !12, i64 64}
!17 = !{!"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}
!18 = !{!17, !7, i64 0}


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