; LLVM IR from openssl/openssl :: crypto/slh_dsa (slh_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.slh_dsa_key_st = type { [128 x i8], ptr, ptr, ptr, i32, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.slh_dsa_params_st = type { ptr, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i64 }

; 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 void @OPENSSL_cleanse(ptr noundef, i64 noundef) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: nounwind uwtable
declare hidden i32 @slh_dsa_compute_pk_root(ptr noundef, ptr noundef, i32 noundef) #3

; Function Attrs: nounwind uwtable
define dso_local i32 @ossl_slh_dsa_generate_key(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, i64 noundef %4) #3 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca i64, align 8
  %15 = alloca i64, align 8
  %16 = alloca ptr, align 8
  %17 = alloca ptr, align 8
  %18 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !5
  store i64 %4, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %19 = load ptr, ptr %8, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.slh_dsa_key_st, ptr %19, i32 0, i32 5
  %21 = load ptr, ptr %20, align 8, !tbaa !11
  %22 = getelementptr inbounds %struct.slh_dsa_params_st, ptr %21, i32 0, i32 3
  %23 = load i32, ptr %22, align 8, !tbaa !14
  %24 = zext i32 %23 to i64
  store i64 %24, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %25 = load i64, ptr %12, align 8, !tbaa !9
  %26 = mul i64 2, %25
  store i64 %26, ptr %13, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %27 = load i64, ptr %12, align 8, !tbaa !9
  store i64 %27, ptr %14, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %28 = load i64, ptr %13, align 8, !tbaa !9
  %29 = load i64, ptr %14, align 8, !tbaa !9
  %30 = add i64 %28, %29
  store i64 %30, ptr %15, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.slh_dsa_key_st, ptr %31, i32 0, i32 0
  %33 = getelementptr inbounds [128 x i8], ptr %32, i64 0, i64 0
  store ptr %33, ptr %16, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #4
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.slh_dsa_key_st, ptr %34, i32 0, i32 0
  %36 = getelementptr inbounds [128 x i8], ptr %35, i64 0, i64 0
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.slh_dsa_key_st, ptr %37, i32 0, i32 5
  %39 = load ptr, ptr %38, align 8, !tbaa !11
  %40 = getelementptr inbounds %struct.slh_dsa_params_st, ptr %39, i32 0, i32 3
  %41 = load i32, ptr %40, align 8, !tbaa !14
  %42 = mul i32 %41, 2
  %43 = zext i32 %42 to i64
  %44 = getelementptr inbounds i8, ptr %36, i64 %43
  store ptr %44, ptr %17, align 8, !tbaa !5
  %45 = load ptr, ptr %10, align 8, !tbaa !5
  %46 = icmp ne ptr %45, null
  br i1 %46, label %47, label %59

47:                                               ; preds = %5
  %48 = load i64, ptr %11, align 8, !tbaa !9
  %49 = icmp ne i64 %48, 0
  br i1 %49, label %50, label %59

50:                                               ; preds = %47
  %51 = load i64, ptr %11, align 8, !tbaa !9
  %52 = load i64, ptr %15, align 8, !tbaa !9
  %53 = icmp ne i64 %51, %52
  br i1 %53, label %54, label %55

54:                                               ; preds = %50
  br label %85

55:                                               ; preds = %50
  %56 = load ptr, ptr %16, align 8, !tbaa !5
  %57 = load ptr, ptr %10, align 8, !tbaa !5
  %58 = load i64, ptr %15, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %56, ptr align 1 %57, i64 %58, i1 false)
  br label %73

59:                                               ; preds = %47, %5
  %60 = load ptr, ptr %9, align 8, !tbaa !5
  %61 = load ptr, ptr %16, align 8, !tbaa !5
  %62 = load i64, ptr %13, align 8, !tbaa !9
  %63 = call i32 @RAND_priv_bytes_ex(ptr noundef %60, ptr noundef %61, i64 noundef %62, i32 noundef 0)
  %64 = icmp sle i32 %63, 0
  br i1 %64, label %71, label %65

65:                                               ; preds = %59
  %66 = load ptr, ptr %9, align 8, !tbaa !5
  %67 = load ptr, ptr %17, align 8, !tbaa !5
  %68 = load i64, ptr %14, align 8, !tbaa !9
  %69 = call i32 @RAND_bytes_ex(ptr noundef %66, ptr noundef %67, i64 noundef %68, i32 noundef 0)
  %70 = icmp sle i32 %69, 0
  br i1 %70, label %71, label %72

71:                                               ; preds = %65, %59
  br label %85

72:                                               ; preds = %65
  br label %73

73:                                               ; preds = %72, %55
  %74 = load ptr, ptr %7, align 8, !tbaa !5
  %75 = load ptr, ptr %8, align 8, !tbaa !5
  %76 = call i32 @slh_dsa_compute_pk_root(ptr noundef %74, ptr noundef %75, i32 noundef 0)
  %77 = icmp ne i32 %76, 0
  br i1 %77, label %79, label %78

78:                                               ; preds = %73
  br label %85

79:                                               ; preds = %73
  %80 = load ptr, ptr %17, align 8, !tbaa !5
  %81 = load ptr, ptr %8, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.slh_dsa_key_st, ptr %81, i32 0, i32 1
  store ptr %80, ptr %82, align 8, !tbaa !16
  %83 = load ptr, ptr %8, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.slh_dsa_key_st, ptr %83, i32 0, i32 4
  store i32 1, ptr %84, align 8, !tbaa !17
  store i32 1, ptr %6, align 4
  store i32 1, ptr %18, align 4
  br label %92

85:                                               ; preds = %78, %71, %54
  %86 = load ptr, ptr %8, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.slh_dsa_key_st, ptr %86, i32 0, i32 1
  store ptr null, ptr %87, align 8, !tbaa !16
  %88 = load ptr, ptr %8, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.slh_dsa_key_st, ptr %88, i32 0, i32 4
  store i32 0, ptr %89, align 8, !tbaa !17
  %90 = load ptr, ptr %16, align 8, !tbaa !5
  %91 = load i64, ptr %13, align 8, !tbaa !9
  call void @OPENSSL_cleanse(ptr noundef %90, i64 noundef %91)
  store i32 0, ptr %6, align 4
  store i32 1, ptr %18, align 4
  br label %92

92:                                               ; preds = %85, %79
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  %93 = load i32, ptr %6, align 4
  ret i32 %93
}

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

declare i32 @RAND_bytes_ex(ptr noundef, ptr noundef, i64 noundef, i32 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { 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, !6, i64 160}
!12 = !{!"slh_dsa_key_st", !7, i64 0, !6, i64 128, !6, i64 136, !6, i64 144, !13, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !6, i64 200}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !13, i64 16}
!15 = !{!"slh_dsa_params_st", !6, i64 0, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20, !13, i64 24, !13, i64 28, !13, i64 32, !13, i64 36, !13, i64 40, !13, i64 44, !13, i64 48, !13, i64 52, !10, i64 56}
!16 = !{!12, !6, i64 128}
!17 = !{!12, !13, i64 152}


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

declare void @OPENSSL_cleanse(ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @ossl_slh_dsa_generate_key(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef readonly %3, i64 noundef %4) local_unnamed_addr #2 {
  %6 = getelementptr inbounds i8, ptr %1, i64 160
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %7, i64 16
  %9 = load i32, ptr %8, align 8, !tbaa !11
  %10 = zext i32 %9 to i64
  %11 = shl nuw nsw i64 %10, 1
  %12 = shl i32 %9, 1
  %13 = zext i32 %12 to i64
  %14 = getelementptr inbounds i8, ptr %1, i64 %13
  %15 = icmp ne ptr %3, null
  %16 = icmp ne i64 %4, 0
  %or.cond = and i1 %15, %16
  br i1 %or.cond, label %17, label %20

17:                                               ; preds = %5
  %18 = mul nuw nsw i64 %10, 3
  %.not = icmp eq i64 %18, %4
  br i1 %.not, label %19, label %31

19:                                               ; preds = %17
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %1, ptr nonnull align 1 %3, i64 %4, i1 false)
  br label %26

20:                                               ; preds = %5
  %21 = tail call i32 @RAND_priv_bytes_ex(ptr noundef %2, ptr noundef nonnull %1, i64 noundef %11, i32 noundef 0) #3
  %22 = icmp slt i32 %21, 1
  br i1 %22, label %31, label %23

23:                                               ; preds = %20
  %24 = tail call i32 @RAND_bytes_ex(ptr noundef %2, ptr noundef nonnull %14, i64 noundef %10, i32 noundef 0) #3
  %25 = icmp slt i32 %24, 1
  br i1 %25, label %31, label %26

26:                                               ; preds = %23, %19
  %27 = tail call i32 @slh_dsa_compute_pk_root(ptr noundef %0, ptr noundef nonnull %1, i32 noundef 0)
  %.not34 = icmp eq i32 %27, 0
  br i1 %.not34, label %31, label %28

28:                                               ; preds = %26
  %29 = getelementptr inbounds i8, ptr %1, i64 128
  store ptr %14, ptr %29, align 8, !tbaa !14
  %30 = getelementptr inbounds i8, ptr %1, i64 152
  store i32 1, ptr %30, align 8, !tbaa !15
  br label %34

31:                                               ; preds = %26, %20, %23, %17
  %32 = getelementptr inbounds i8, ptr %1, i64 128
  store ptr null, ptr %32, align 8, !tbaa !14
  %33 = getelementptr inbounds i8, ptr %1, i64 152
  store i32 0, ptr %33, align 8, !tbaa !15
  tail call void @OPENSSL_cleanse(ptr noundef nonnull %1, i64 noundef %11) #3
  br label %34

34:                                               ; preds = %31, %28
  %.0 = phi i32 [ 0, %31 ], [ 1, %28 ]
  ret i32 %.0
}

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

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

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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !9, i64 160}
!6 = !{!"slh_dsa_key_st", !7, i64 0, !9, i64 128, !9, i64 136, !9, i64 144, !10, i64 152, !9, i64 160, !9, i64 168, !9, i64 176, !9, i64 184, !9, i64 192, !9, i64 200}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"any pointer", !7, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 16}
!12 = !{!"slh_dsa_params_st", !9, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52, !13, i64 56}
!13 = !{!"long", !7, i64 0}
!14 = !{!6, !9, i64 128}
!15 = !{!6, !10, i64 152}


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