; 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 }
%struct.poly_st = type { [256 x i32] }

; 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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @vector_alloc(ptr noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @ossl_ml_dsa_key_priv_alloc(ptr noundef %0) #2 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.ml_dsa_key_st, ptr %8, i32 0, i32 1
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  %11 = getelementptr inbounds %struct.ml_dsa_params_st, ptr %10, i32 0, i32 6
  %12 = load i64, ptr %11, align 8, !tbaa !14
  store i64 %12, ptr %4, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.ml_dsa_key_st, ptr %13, i32 0, i32 1
  %15 = load ptr, ptr %14, align 8, !tbaa !9
  %16 = getelementptr inbounds %struct.ml_dsa_params_st, ptr %15, i32 0, i32 7
  %17 = load i64, ptr %16, align 8, !tbaa !17
  store i64 %17, ptr %5, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.ml_dsa_key_st, ptr %18, i32 0, i32 14
  %20 = getelementptr inbounds %struct.vector_st, ptr %19, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !18
  %22 = icmp ne ptr %21, null
  br i1 %22, label %23, label %24

23:                                               ; preds = %1
  store i32 0, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %57

24:                                               ; preds = %1
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.ml_dsa_key_st, ptr %25, i32 0, i32 14
  %27 = load i64, ptr %5, align 8, !tbaa !16
  %28 = load i64, ptr %4, align 8, !tbaa !16
  %29 = mul i64 2, %28
  %30 = add i64 %27, %29
  %31 = call i32 @vector_alloc(ptr noundef %26, i64 noundef %30)
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %34, label %33

33:                                               ; preds = %24
  store i32 0, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %57

34:                                               ; preds = %24
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.ml_dsa_key_st, ptr %35, i32 0, i32 14
  %37 = getelementptr inbounds %struct.vector_st, ptr %36, i32 0, i32 0
  %38 = load ptr, ptr %37, align 8, !tbaa !18
  store ptr %38, ptr %6, align 8, !tbaa !5
  %39 = load i64, ptr %5, align 8, !tbaa !16
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.ml_dsa_key_st, ptr %40, i32 0, i32 14
  %42 = getelementptr inbounds %struct.vector_st, ptr %41, i32 0, i32 1
  store i64 %39, ptr %42, align 8, !tbaa !19
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.ml_dsa_key_st, ptr %43, i32 0, i32 13
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = load i64, ptr %5, align 8, !tbaa !16
  %47 = getelementptr inbounds %struct.poly_st, ptr %45, i64 %46
  %48 = load i64, ptr %4, align 8, !tbaa !16
  call void @vector_init(ptr noundef %44, ptr noundef %47, i64 noundef %48)
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.ml_dsa_key_st, ptr %49, i32 0, i32 12
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = load i64, ptr %5, align 8, !tbaa !16
  %53 = getelementptr inbounds %struct.poly_st, ptr %51, i64 %52
  %54 = load i64, ptr %4, align 8, !tbaa !16
  %55 = getelementptr inbounds %struct.poly_st, ptr %53, i64 %54
  %56 = load i64, ptr %4, align 8, !tbaa !16
  call void @vector_init(ptr noundef %50, ptr noundef %55, i64 noundef %56)
  store i32 1, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %57

57:                                               ; preds = %34, %33, %23
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %58 = load i32, ptr %2, align 4
  ret i32 %58
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @vector_init(ptr noundef, ptr noundef, i64 noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 = { 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, !6, i64 8}
!10 = !{!"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, !11, i64 184, !12, i64 192, !12, i64 208, !12, i64 224, !12, i64 240}
!11 = !{!"int", !7, i64 0}
!12 = !{!"vector_st", !6, i64 0, !13, i64 8}
!13 = !{!"long", !7, i64 0}
!14 = !{!15, !13, i64 32}
!15 = !{!"ml_dsa_params_st", !6, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !13, i64 32, !13, i64 40, !11, i64 48, !11, i64 52, !11, i64 56, !11, i64 60, !13, i64 64, !13, i64 72, !13, i64 80}
!16 = !{!13, !13, i64 0}
!17 = !{!15, !13, i64 40}
!18 = !{!10, !6, i64 240}
!19 = !{!10, !13, i64 248}


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

%struct.poly_st = type { [256 x i32] }

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @ossl_ml_dsa_key_priv_alloc(ptr noundef %0) local_unnamed_addr #1 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %3, i64 32
  %5 = load i64, ptr %4, align 8, !tbaa !13
  %6 = getelementptr inbounds i8, ptr %3, i64 40
  %7 = load i64, ptr %6, align 8, !tbaa !15
  %8 = getelementptr inbounds i8, ptr %0, i64 240
  %9 = load ptr, ptr %8, align 8, !tbaa !16
  %.not = icmp eq ptr %9, null
  br i1 %.not, label %10, label %21

10:                                               ; preds = %1
  %11 = shl i64 %5, 1
  %12 = add i64 %7, %11
  %13 = tail call i32 @vector_alloc(ptr noundef nonnull %8, i64 noundef %12)
  %.not18 = icmp eq i32 %13, 0
  br i1 %.not18, label %21, label %14

14:                                               ; preds = %10
  %15 = load ptr, ptr %8, align 8, !tbaa !16
  %16 = getelementptr inbounds i8, ptr %0, i64 248
  store i64 %7, ptr %16, align 8, !tbaa !17
  %17 = getelementptr inbounds i8, ptr %0, i64 224
  %18 = getelementptr inbounds %struct.poly_st, ptr %15, i64 %7
  tail call void @vector_init(ptr noundef nonnull %17, ptr noundef %18, i64 noundef %5)
  %19 = getelementptr inbounds i8, ptr %0, i64 208
  %20 = getelementptr inbounds %struct.poly_st, ptr %18, i64 %5
  tail call void @vector_init(ptr noundef nonnull %19, ptr noundef %20, i64 noundef %5)
  br label %21

21:                                               ; preds = %10, %1, %14
  %.0 = phi i32 [ 1, %14 ], [ 0, %1 ], [ 0, %10 ]
  ret i32 %.0
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @vector_init(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

attributes #0 = { inlinehint 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 = { 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" }

!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 32}
!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 = !{!14, !12, i64 40}
!16 = !{!6, !7, i64 240}
!17 = !{!6, !12, i64 248}


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