; 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_adrs_func_st = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.slh_hash_func_st = type { ptr, ptr, ptr, ptr, ptr, ptr }

; Function Attrs: nounwind uwtable
define dso_local i32 @ossl_slh_xmss_node(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef %4, ptr noundef %5, ptr noundef %6, i64 noundef %7) #0 {
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca i64, align 8
  %18 = alloca ptr, align 8
  %19 = alloca ptr, align 8
  %20 = alloca i32, align 4
  %21 = alloca [32 x i8], align 16
  %22 = alloca [32 x i8], align 16
  store ptr %0, ptr %10, align 8, !tbaa !5
  store ptr %1, ptr %11, align 8, !tbaa !5
  store i32 %2, ptr %12, align 4, !tbaa !9
  store i32 %3, ptr %13, align 4, !tbaa !9
  store ptr %4, ptr %14, align 8, !tbaa !5
  store ptr %5, ptr %15, align 8, !tbaa !5
  store ptr %6, ptr %16, align 8, !tbaa !5
  store i64 %7, ptr %17, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #3
  %23 = load ptr, ptr %10, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.slh_dsa_hash_ctx_st, ptr %23, i32 0, i32 0
  %25 = load ptr, ptr %24, align 8, !tbaa !13
  store ptr %25, ptr %18, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #3
  %26 = load ptr, ptr %18, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.slh_dsa_key_st, ptr %26, i32 0, i32 6
  %28 = load ptr, ptr %27, align 8, !tbaa !15
  store ptr %28, ptr %19, align 8, !tbaa !5
  %29 = load i32, ptr %13, align 4, !tbaa !9
  %30 = icmp eq i32 %29, 0
  br i1 %30, label %31, label %51

31:                                               ; preds = %8
  %32 = load ptr, ptr %19, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.slh_adrs_func_st, ptr %32, i32 0, i32 2
  %34 = load ptr, ptr %33, align 8, !tbaa !17
  %35 = load ptr, ptr %15, align 8, !tbaa !5
  call void %34(ptr noundef %35, i32 noundef 0)
  %36 = load ptr, ptr %19, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.slh_adrs_func_st, ptr %36, i32 0, i32 3
  %38 = load ptr, ptr %37, align 8, !tbaa !19
  %39 = load ptr, ptr %15, align 8, !tbaa !5
  %40 = load i32, ptr %12, align 4, !tbaa !9
  call void %38(ptr noundef %39, i32 noundef %40)
  %41 = load ptr, ptr %10, align 8, !tbaa !5
  %42 = load ptr, ptr %11, align 8, !tbaa !5
  %43 = load ptr, ptr %14, align 8, !tbaa !5
  %44 = load ptr, ptr %15, align 8, !tbaa !5
  %45 = load ptr, ptr %16, align 8, !tbaa !5
  %46 = load i64, ptr %17, align 8, !tbaa !11
  %47 = call i32 @ossl_slh_wots_pk_gen(ptr noundef %41, ptr noundef %42, ptr noundef %43, ptr noundef %44, ptr noundef %45, i64 noundef %46)
  %48 = icmp ne i32 %47, 0
  br i1 %48, label %50, label %49

49:                                               ; preds = %31
  store i32 0, ptr %9, align 4
  store i32 1, ptr %20, align 4
  br label %112

50:                                               ; preds = %31
  br label %111

51:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 32, ptr %21) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr %22) #3
  %52 = load ptr, ptr %10, align 8, !tbaa !5
  %53 = load ptr, ptr %11, align 8, !tbaa !5
  %54 = load i32, ptr %12, align 4, !tbaa !9
  %55 = mul i32 2, %54
  %56 = load i32, ptr %13, align 4, !tbaa !9
  %57 = sub i32 %56, 1
  %58 = load ptr, ptr %14, align 8, !tbaa !5
  %59 = load ptr, ptr %15, align 8, !tbaa !5
  %60 = getelementptr inbounds [32 x i8], ptr %21, i64 0, i64 0
  %61 = call i32 @ossl_slh_xmss_node(ptr noundef %52, ptr noundef %53, i32 noundef %55, i32 noundef %57, ptr noundef %58, ptr noundef %59, ptr noundef %60, i64 noundef 32)
  %62 = icmp ne i32 %61, 0
  br i1 %62, label %63, label %76

63:                                               ; preds = %51
  %64 = load ptr, ptr %10, align 8, !tbaa !5
  %65 = load ptr, ptr %11, align 8, !tbaa !5
  %66 = load i32, ptr %12, align 4, !tbaa !9
  %67 = mul i32 2, %66
  %68 = add i32 %67, 1
  %69 = load i32, ptr %13, align 4, !tbaa !9
  %70 = sub i32 %69, 1
  %71 = load ptr, ptr %14, align 8, !tbaa !5
  %72 = load ptr, ptr %15, align 8, !tbaa !5
  %73 = getelementptr inbounds [32 x i8], ptr %22, i64 0, i64 0
  %74 = call i32 @ossl_slh_xmss_node(ptr noundef %64, ptr noundef %65, i32 noundef %68, i32 noundef %70, ptr noundef %71, ptr noundef %72, ptr noundef %73, i64 noundef 32)
  %75 = icmp ne i32 %74, 0
  br i1 %75, label %77, label %76

76:                                               ; preds = %63, %51
  store i32 0, ptr %9, align 4
  store i32 1, ptr %20, align 4
  br label %108

77:                                               ; preds = %63
  %78 = load ptr, ptr %19, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.slh_adrs_func_st, ptr %78, i32 0, i32 2
  %80 = load ptr, ptr %79, align 8, !tbaa !17
  %81 = load ptr, ptr %15, align 8, !tbaa !5
  call void %80(ptr noundef %81, i32 noundef 2)
  %82 = load ptr, ptr %19, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.slh_adrs_func_st, ptr %82, i32 0, i32 6
  %84 = load ptr, ptr %83, align 8, !tbaa !20
  %85 = load ptr, ptr %15, align 8, !tbaa !5
  %86 = load i32, ptr %13, align 4, !tbaa !9
  call void %84(ptr noundef %85, i32 noundef %86)
  %87 = load ptr, ptr %19, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.slh_adrs_func_st, ptr %87, i32 0, i32 8
  %89 = load ptr, ptr %88, align 8, !tbaa !21
  %90 = load ptr, ptr %15, align 8, !tbaa !5
  %91 = load i32, ptr %12, align 4, !tbaa !9
  call void %89(ptr noundef %90, i32 noundef %91)
  %92 = load ptr, ptr %18, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.slh_dsa_key_st, ptr %92, i32 0, i32 7
  %94 = load ptr, ptr %93, align 8, !tbaa !22
  %95 = getelementptr inbounds %struct.slh_hash_func_st, ptr %94, i32 0, i32 4
  %96 = load ptr, ptr %95, align 8, !tbaa !23
  %97 = load ptr, ptr %10, align 8, !tbaa !5
  %98 = load ptr, ptr %14, align 8, !tbaa !5
  %99 = load ptr, ptr %15, align 8, !tbaa !5
  %100 = getelementptr inbounds [32 x i8], ptr %21, i64 0, i64 0
  %101 = getelementptr inbounds [32 x i8], ptr %22, i64 0, i64 0
  %102 = load ptr, ptr %16, align 8, !tbaa !5
  %103 = load i64, ptr %17, align 8, !tbaa !11
  %104 = call i32 %96(ptr noundef %97, ptr noundef %98, ptr noundef %99, ptr noundef %100, ptr noundef %101, ptr noundef %102, i64 noundef %103)
  %105 = icmp ne i32 %104, 0
  br i1 %105, label %107, label %106

106:                                              ; preds = %77
  store i32 0, ptr %9, align 4
  store i32 1, ptr %20, align 4
  br label %108

107:                                              ; preds = %77
  store i32 0, ptr %20, align 4
  br label %108

108:                                              ; preds = %107, %106, %76
  call void @llvm.lifetime.end.p0(i64 32, ptr %22) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr %21) #3
  %109 = load i32, ptr %20, align 4
  switch i32 %109, label %112 [
    i32 0, label %110
  ]

110:                                              ; preds = %108
  br label %111

111:                                              ; preds = %110, %50
  store i32 1, ptr %9, align 4
  store i32 1, ptr %20, align 4
  br label %112

112:                                              ; preds = %111, %108, %49
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #3
  %113 = load i32, ptr %9, align 4
  ret i32 %113
}

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

declare i32 @ossl_slh_wots_pk_gen(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, i64 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 0}
!14 = !{!"slh_dsa_hash_ctx_st", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !10, i64 32}
!15 = !{!16, !6, i64 168}
!16 = !{!"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}
!17 = !{!18, !6, i64 16}
!18 = !{!"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}
!19 = !{!18, !6, i64 24}
!20 = !{!18, !6, i64 48}
!21 = !{!18, !6, i64 64}
!22 = !{!16, !6, i64 176}
!23 = !{!24, !6, i64 32}
!24 = !{!"slh_hash_func_st", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}


; 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
define dso_local range(i32 0, 2) i32 @ossl_slh_xmss_node(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef %4, ptr noundef %5, ptr noundef %6, i64 noundef %7) local_unnamed_addr #0 {
  %9 = alloca [32 x i8], align 16
  %10 = alloca [32 x i8], align 16
  %11 = load ptr, ptr %0, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %11, i64 168
  %13 = load ptr, ptr %12, align 8, !tbaa !11
  %14 = icmp eq i32 %3, 0
  br i1 %14, label %15, label %21

15:                                               ; preds = %8
  %16 = getelementptr inbounds i8, ptr %13, i64 16
  %17 = load ptr, ptr %16, align 8, !tbaa !13
  tail call void %17(ptr noundef %5, i32 noundef 0) #3
  %18 = getelementptr inbounds i8, ptr %13, i64 24
  %19 = load ptr, ptr %18, align 8, !tbaa !15
  tail call void %19(ptr noundef %5, i32 noundef %2) #3
  %20 = tail call i32 @ossl_slh_wots_pk_gen(ptr noundef nonnull %0, ptr noundef %1, ptr noundef %4, ptr noundef %5, ptr noundef %6, i64 noundef %7) #3
  %.not45 = icmp eq i32 %20, 0
  br i1 %.not45, label %41, label %40

21:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %9) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %10) #3
  %22 = shl i32 %2, 1
  %23 = add i32 %3, -1
  %24 = call i32 @ossl_slh_xmss_node(ptr noundef nonnull %0, ptr noundef %1, i32 noundef %22, i32 noundef %23, ptr noundef %4, ptr noundef %5, ptr noundef nonnull %9, i64 noundef 32)
  %.not = icmp eq i32 %24, 0
  br i1 %.not, label %.critedge, label %25

25:                                               ; preds = %21
  %26 = or disjoint i32 %22, 1
  %27 = call i32 @ossl_slh_xmss_node(ptr noundef nonnull %0, ptr noundef %1, i32 noundef %26, i32 noundef %23, ptr noundef %4, ptr noundef %5, ptr noundef nonnull %10, i64 noundef 32)
  %.not43 = icmp eq i32 %27, 0
  br i1 %.not43, label %.critedge, label %28

28:                                               ; preds = %25
  %29 = getelementptr inbounds i8, ptr %13, i64 16
  %30 = load ptr, ptr %29, align 8, !tbaa !13
  call void %30(ptr noundef %5, i32 noundef 2) #3
  %31 = getelementptr inbounds i8, ptr %13, i64 48
  %32 = load ptr, ptr %31, align 8, !tbaa !16
  call void %32(ptr noundef %5, i32 noundef %3) #3
  %33 = getelementptr inbounds i8, ptr %13, i64 64
  %34 = load ptr, ptr %33, align 8, !tbaa !17
  call void %34(ptr noundef %5, i32 noundef %2) #3
  %35 = getelementptr inbounds i8, ptr %11, i64 176
  %36 = load ptr, ptr %35, align 8, !tbaa !18
  %37 = getelementptr inbounds i8, ptr %36, i64 32
  %38 = load ptr, ptr %37, align 8, !tbaa !19
  %39 = call i32 %38(ptr noundef nonnull %0, ptr noundef %4, ptr noundef %5, ptr noundef nonnull %9, ptr noundef nonnull %10, ptr noundef %6, i64 noundef %7) #3
  %.not44.not = icmp eq i32 %39, 0
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %10) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %9) #3
  br i1 %.not44.not, label %41, label %40

40:                                               ; preds = %28, %15
  br label %41

.critedge:                                        ; preds = %21, %25
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %10) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %9) #3
  br label %41

41:                                               ; preds = %.critedge, %15, %28, %40
  %.1 = phi i32 [ 1, %40 ], [ 0, %28 ], [ 0, %15 ], [ 0, %.critedge ]
  ret i32 %.1
}

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

declare i32 @ossl_slh_wots_pk_gen(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress 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 = { 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 = !{!14, !7, i64 16}
!14 = !{!"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}
!15 = !{!14, !7, i64 24}
!16 = !{!14, !7, i64 48}
!17 = !{!14, !7, i64 64}
!18 = !{!12, !7, i64 176}
!19 = !{!20, !7, i64 32}
!20 = !{!"slh_hash_func_st", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40}


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