; LLVM IR from openssl/openssl :: crypto/slh_dsa (slh_xmss)

; 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_hash_ctx_st = type { ptr, ptr, ptr, ptr, i32 }
%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 }
%struct.slh_adrs_func_st = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }

; Function Attrs: nounwind uwtable
declare dso_local i32 @ossl_slh_xmss_node(ptr noundef, ptr noundef, i32 noundef, i32 noundef, ptr noundef, ptr 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

; 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
define dso_local i32 @ossl_slh_xmss_sign(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, ptr noundef %4, ptr noundef %5, ptr noundef %6) #0 {
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca ptr, align 8
  %18 = alloca [32 x i8], align 16
  %19 = alloca i64, align 8
  %20 = alloca i32, align 4
  %21 = alloca i32, align 4
  %22 = alloca i32, align 4
  %23 = alloca ptr, align 8
  %24 = alloca i64, align 8
  %25 = alloca i32, align 4
  store ptr %0, ptr %9, align 8, !tbaa !5
  store ptr %1, ptr %10, align 8, !tbaa !5
  store ptr %2, ptr %11, align 8, !tbaa !5
  store i32 %3, ptr %12, align 4, !tbaa !9
  store ptr %4, ptr %13, align 8, !tbaa !5
  store ptr %5, ptr %14, align 8, !tbaa !5
  store ptr %6, ptr %15, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  %26 = load ptr, ptr %9, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.slh_dsa_hash_ctx_st, ptr %26, i32 0, i32 0
  %28 = load ptr, ptr %27, align 8, !tbaa !11
  store ptr %28, ptr %16, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #3
  %29 = load ptr, ptr %16, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.slh_dsa_key_st, ptr %29, i32 0, i32 6
  %31 = load ptr, ptr %30, align 8, !tbaa !13
  store ptr %31, ptr %17, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 32, ptr %18) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #3
  %32 = load ptr, ptr %16, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.slh_dsa_key_st, ptr %32, i32 0, i32 5
  %34 = load ptr, ptr %33, align 8, !tbaa !15
  %35 = getelementptr inbounds %struct.slh_dsa_params_st, ptr %34, i32 0, i32 3
  %36 = load i32, ptr %35, align 8, !tbaa !16
  %37 = zext i32 %36 to i64
  store i64 %37, ptr %19, align 8, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #3
  %38 = load ptr, ptr %16, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.slh_dsa_key_st, ptr %38, i32 0, i32 5
  %40 = load ptr, ptr %39, align 8, !tbaa !15
  %41 = getelementptr inbounds %struct.slh_dsa_params_st, ptr %40, i32 0, i32 6
  %42 = load i32, ptr %41, align 4, !tbaa !20
  store i32 %42, ptr %21, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %22) #3
  %43 = load i32, ptr %12, align 4, !tbaa !9
  store i32 %43, ptr %22, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %23) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %24) #3
  %44 = load i64, ptr %19, align 8, !tbaa !19
  store i64 %44, ptr %24, align 8, !tbaa !19
  %45 = load ptr, ptr %17, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.slh_adrs_func_st, ptr %45, i32 0, i32 10
  %47 = load ptr, ptr %46, align 8, !tbaa !21
  %48 = getelementptr inbounds [32 x i8], ptr %18, i64 0, i64 0
  %49 = load ptr, ptr %14, align 8, !tbaa !5
  call void %47(ptr noundef %48, ptr noundef %49)
  %50 = load ptr, ptr %17, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.slh_adrs_func_st, ptr %50, i32 0, i32 2
  %52 = load ptr, ptr %51, align 8, !tbaa !23
  %53 = load ptr, ptr %14, align 8, !tbaa !5
  call void %52(ptr noundef %53, i32 noundef 0)
  %54 = load ptr, ptr %17, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.slh_adrs_func_st, ptr %54, i32 0, i32 3
  %56 = load ptr, ptr %55, align 8, !tbaa !24
  %57 = load ptr, ptr %14, align 8, !tbaa !5
  %58 = load i32, ptr %12, align 4, !tbaa !9
  call void %56(ptr noundef %57, i32 noundef %58)
  %59 = load ptr, ptr %9, align 8, !tbaa !5
  %60 = load ptr, ptr %10, align 8, !tbaa !5
  %61 = load ptr, ptr %11, align 8, !tbaa !5
  %62 = load ptr, ptr %13, align 8, !tbaa !5
  %63 = load ptr, ptr %14, align 8, !tbaa !5
  %64 = load ptr, ptr %15, align 8, !tbaa !5
  %65 = call i32 @ossl_slh_wots_sign(ptr noundef %59, ptr noundef %60, ptr noundef %61, ptr noundef %62, ptr noundef %63, ptr noundef %64)
  %66 = icmp ne i32 %65, 0
  br i1 %66, label %68, label %67

67:                                               ; preds = %7
  store i32 0, ptr %8, align 4
  store i32 1, ptr %25, align 4
  br label %103

68:                                               ; preds = %7
  %69 = load ptr, ptr %17, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.slh_adrs_func_st, ptr %69, i32 0, i32 10
  %71 = load ptr, ptr %70, align 8, !tbaa !21
  %72 = load ptr, ptr %14, align 8, !tbaa !5
  %73 = getelementptr inbounds [32 x i8], ptr %18, i64 0, i64 0
  call void %71(ptr noundef %72, ptr noundef %73)
  store i32 0, ptr %20, align 4, !tbaa !9
  br label %74

74:                                               ; preds = %99, %68
  %75 = load i32, ptr %20, align 4, !tbaa !9
  %76 = load i32, ptr %21, align 4, !tbaa !9
  %77 = icmp ult i32 %75, %76
  br i1 %77, label %78, label %102

78:                                               ; preds = %74
  %79 = load ptr, ptr %15, align 8, !tbaa !5
  %80 = load i64, ptr %24, align 8, !tbaa !19
  %81 = call i32 @WPACKET_allocate_bytes(ptr noundef %79, i64 noundef %80, ptr noundef %23)
  %82 = icmp ne i32 %81, 0
  br i1 %82, label %83, label %95

83:                                               ; preds = %78
  %84 = load ptr, ptr %9, align 8, !tbaa !5
  %85 = load ptr, ptr %11, align 8, !tbaa !5
  %86 = load i32, ptr %22, align 4, !tbaa !9
  %87 = xor i32 %86, 1
  %88 = load i32, ptr %20, align 4, !tbaa !9
  %89 = load ptr, ptr %13, align 8, !tbaa !5
  %90 = load ptr, ptr %14, align 8, !tbaa !5
  %91 = load ptr, ptr %23, align 8, !tbaa !5
  %92 = load i64, ptr %24, align 8, !tbaa !19
  %93 = call i32 @ossl_slh_xmss_node(ptr noundef %84, ptr noundef %85, i32 noundef %87, i32 noundef %88, ptr noundef %89, ptr noundef %90, ptr noundef %91, i64 noundef %92)
  %94 = icmp ne i32 %93, 0
  br i1 %94, label %96, label %95

95:                                               ; preds = %83, %78
  store i32 0, ptr %8, align 4
  store i32 1, ptr %25, align 4
  br label %103

96:                                               ; preds = %83
  %97 = load i32, ptr %22, align 4, !tbaa !9
  %98 = lshr i32 %97, 1
  store i32 %98, ptr %22, align 4, !tbaa !9
  br label %99

99:                                               ; preds = %96
  %100 = load i32, ptr %20, align 4, !tbaa !9
  %101 = add i32 %100, 1
  store i32 %101, ptr %20, align 4, !tbaa !9
  br label %74, !llvm.loop !25

102:                                              ; preds = %74
  store i32 1, ptr %8, align 4
  store i32 1, ptr %25, align 4
  br label %103

103:                                              ; preds = %102, %95, %67
  call void @llvm.lifetime.end.p0(i64 8, ptr %24) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %23) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %22) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr %18) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  %104 = load i32, ptr %8, align 4
  ret i32 %104
}

declare i32 @ossl_slh_wots_sign(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #2

declare i32 @WPACKET_allocate_bytes(ptr noundef, i64 noundef, ptr noundef) #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 = { 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, !6, i64 0}
!12 = !{!"slh_dsa_hash_ctx_st", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !10, i64 32}
!13 = !{!14, !6, i64 168}
!14 = !{!"slh_dsa_key_st", !7, i64 0, !6, i64 128, !6, i64 136, !6, i64 144, !10, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !6, i64 200}
!15 = !{!14, !6, i64 160}
!16 = !{!17, !10, i64 16}
!17 = !{!"slh_dsa_params_st", !6, 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, !18, i64 56}
!18 = !{!"long", !7, i64 0}
!19 = !{!18, !18, i64 0}
!20 = !{!17, !10, i64 28}
!21 = !{!22, !6, i64 80}
!22 = !{!"slh_adrs_func_st", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80}
!23 = !{!22, !6, i64 16}
!24 = !{!22, !6, i64 24}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.mustprogress"}


; 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 i32 @ossl_slh_xmss_node(ptr noundef, ptr noundef, i32 noundef, i32 noundef, ptr noundef, ptr 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

; 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
define dso_local range(i32 0, 2) i32 @ossl_slh_xmss_sign(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, ptr noundef %4, ptr noundef %5, ptr noundef %6) local_unnamed_addr #0 {
  %8 = alloca [32 x i8], align 16
  %9 = alloca ptr, align 8
  %10 = load ptr, ptr %0, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %10, i64 168
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %8) #3
  %13 = getelementptr inbounds i8, ptr %10, i64 160
  %14 = load ptr, ptr %13, align 8, !tbaa !13
  %15 = getelementptr inbounds i8, ptr %14, i64 16
  %16 = load i32, ptr %15, align 8, !tbaa !14
  %17 = zext i32 %16 to i64
  %18 = getelementptr inbounds i8, ptr %14, i64 28
  %19 = load i32, ptr %18, align 4, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %9) #3
  %20 = getelementptr inbounds i8, ptr %12, i64 80
  %21 = load ptr, ptr %20, align 8, !tbaa !18
  call void %21(ptr noundef nonnull %8, ptr noundef %5) #3
  %22 = getelementptr inbounds i8, ptr %12, i64 16
  %23 = load ptr, ptr %22, align 8, !tbaa !20
  call void %23(ptr noundef %5, i32 noundef 0) #3
  %24 = getelementptr inbounds i8, ptr %12, i64 24
  %25 = load ptr, ptr %24, align 8, !tbaa !21
  call void %25(ptr noundef %5, i32 noundef %3) #3
  %26 = call i32 @ossl_slh_wots_sign(ptr noundef nonnull %0, ptr noundef %1, ptr noundef %2, ptr noundef %4, ptr noundef %5, ptr noundef %6) #3
  %.not = icmp eq i32 %26, 0
  br i1 %.not, label %.loopexit, label %27

27:                                               ; preds = %7
  %28 = load ptr, ptr %20, align 8, !tbaa !18
  call void %28(ptr noundef %5, ptr noundef nonnull %8) #3
  %.not44 = icmp eq i32 %19, 0
  br i1 %.not44, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %27, %34
  %.03439 = phi i32 [ %35, %34 ], [ %3, %27 ]
  %.03538 = phi i32 [ %36, %34 ], [ 0, %27 ]
  %29 = call i32 @WPACKET_allocate_bytes(ptr noundef %6, i64 noundef %17, ptr noundef nonnull %9) #3
  %.not36 = icmp eq i32 %29, 0
  br i1 %.not36, label %.loopexit, label %30

30:                                               ; preds = %.lr.ph
  %31 = xor i32 %.03439, 1
  %32 = load ptr, ptr %9, align 8, !tbaa !22
  %33 = call i32 @ossl_slh_xmss_node(ptr noundef nonnull %0, ptr noundef %2, i32 noundef %31, i32 noundef %.03538, ptr noundef %4, ptr noundef %5, ptr noundef %32, i64 noundef %17)
  %.not37 = icmp eq i32 %33, 0
  br i1 %.not37, label %.loopexit, label %34

34:                                               ; preds = %30
  %35 = lshr i32 %.03439, 1
  %36 = add nuw i32 %.03538, 1
  %exitcond.not = icmp eq i32 %36, %19
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !23

.loopexit:                                        ; preds = %30, %.lr.ph, %34, %27, %7
  %.0 = phi i32 [ 0, %7 ], [ 1, %27 ], [ 0, %30 ], [ 0, %.lr.ph ], [ 1, %34 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %9) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %8) #3
  ret i32 %.0
}

declare i32 @ossl_slh_wots_sign(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare i32 @WPACKET_allocate_bytes(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #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 = { 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 0}
!6 = !{!"slh_dsa_hash_ctx_st", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!12, !7, i64 168}
!12 = !{!"slh_dsa_key_st", !8, i64 0, !7, i64 128, !7, i64 136, !7, i64 144, !10, i64 152, !7, i64 160, !7, i64 168, !7, i64 176, !7, i64 184, !7, i64 192, !7, i64 200}
!13 = !{!12, !7, i64 160}
!14 = !{!15, !10, i64 16}
!15 = !{!"slh_dsa_params_st", !7, 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, !16, i64 56}
!16 = !{!"long", !8, i64 0}
!17 = !{!15, !10, i64 28}
!18 = !{!19, !7, i64 80}
!19 = !{!"slh_adrs_func_st", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !7, i64 80}
!20 = !{!19, !7, i64 16}
!21 = !{!19, !7, i64 24}
!22 = !{!7, !7, i64 0}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass