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

; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; 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) #1

declare i32 @ossl_slh_xmss_pk_from_sig(ptr noundef, i32 noundef, 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) #0

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

56:                                               ; preds = %91, %7
  %57 = load i32, ptr %25, align 4, !tbaa !11
  %58 = load i32, ptr %23, align 4, !tbaa !11
  %59 = icmp ult i32 %57, %58
  br i1 %59, label %60, label %94

60:                                               ; preds = %56
  %61 = load ptr, ptr %17, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.slh_adrs_func_st, ptr %61, i32 0, i32 0
  %63 = load ptr, ptr %62, align 8, !tbaa !24
  %64 = getelementptr inbounds [32 x i8], ptr %18, i64 0, i64 0
  %65 = load i32, ptr %25, align 4, !tbaa !11
  call void %63(ptr noundef %64, i32 noundef %65)
  %66 = load ptr, ptr %17, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.slh_adrs_func_st, ptr %66, i32 0, i32 1
  %68 = load ptr, ptr %67, align 8, !tbaa !25
  %69 = getelementptr inbounds [32 x i8], ptr %18, i64 0, i64 0
  %70 = load i64, ptr %13, align 8, !tbaa !9
  call void %68(ptr noundef %69, i64 noundef %70)
  %71 = load ptr, ptr %9, align 8, !tbaa !5
  %72 = load i32, ptr %14, align 4, !tbaa !11
  %73 = load ptr, ptr %11, align 8, !tbaa !5
  %74 = getelementptr inbounds [32 x i8], ptr %19, i64 0, i64 0
  %75 = load ptr, ptr %12, align 8, !tbaa !5
  %76 = getelementptr inbounds [32 x i8], ptr %18, i64 0, i64 0
  %77 = getelementptr inbounds [32 x i8], ptr %19, i64 0, i64 0
  %78 = call i32 @ossl_slh_xmss_pk_from_sig(ptr noundef %71, i32 noundef %72, ptr noundef %73, ptr noundef %74, ptr noundef %75, ptr noundef %76, ptr noundef %77, i64 noundef 32)
  %79 = icmp ne i32 %78, 0
  br i1 %79, label %81, label %80

80:                                               ; preds = %60
  store i32 0, ptr %8, align 4
  store i32 1, ptr %26, align 4
  br label %102

81:                                               ; preds = %60
  %82 = load i64, ptr %13, align 8, !tbaa !9
  %83 = load i32, ptr %24, align 4, !tbaa !11
  %84 = zext i32 %83 to i64
  %85 = and i64 %82, %84
  %86 = trunc i64 %85 to i32
  store i32 %86, ptr %14, align 4, !tbaa !11
  %87 = load i32, ptr %21, align 4, !tbaa !11
  %88 = load i64, ptr %13, align 8, !tbaa !9
  %89 = zext i32 %87 to i64
  %90 = lshr i64 %88, %89
  store i64 %90, ptr %13, align 8, !tbaa !9
  br label %91

91:                                               ; preds = %81
  %92 = load i32, ptr %25, align 4, !tbaa !11
  %93 = add i32 %92, 1
  store i32 %93, ptr %25, align 4, !tbaa !11
  br label %56, !llvm.loop !26

94:                                               ; preds = %56
  %95 = getelementptr inbounds [32 x i8], ptr %19, i64 0, i64 0
  %96 = load ptr, ptr %15, align 8, !tbaa !5
  %97 = load i32, ptr %22, align 4, !tbaa !11
  %98 = zext i32 %97 to i64
  %99 = call i32 @memcmp(ptr noundef %95, ptr noundef %96, i64 noundef %98) #6
  %100 = icmp eq i32 %99, 0
  %101 = zext i1 %100 to i32
  store i32 %101, ptr %8, align 4
  store i32 1, ptr %26, align 4
  br label %102

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

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree 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 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 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 #5 = { nounwind }
attributes #6 = { 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, !12, i64 0}
!12 = !{!"int", !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, !12, i64 32}
!15 = !{!16, !6, i64 168}
!16 = !{!"slh_dsa_key_st", !7, i64 0, !6, i64 128, !6, i64 136, !6, i64 144, !12, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !6, i64 200}
!17 = !{!16, !6, i64 160}
!18 = !{!19, !12, i64 28}
!19 = !{!"slh_dsa_params_st", !6, i64 0, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20, !12, i64 24, !12, i64 28, !12, i64 32, !12, i64 36, !12, i64 40, !12, i64 44, !12, i64 48, !12, i64 52, !10, i64 56}
!20 = !{!19, !12, i64 16}
!21 = !{!19, !12, i64 24}
!22 = !{!23, !6, i64 72}
!23 = !{!"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}
!24 = !{!23, !6, i64 0}
!25 = !{!23, !6, i64 8}
!26 = distinct !{!26, !27}
!27 = !{!"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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #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

declare i32 @ossl_slh_xmss_pk_from_sig(ptr noundef, i32 noundef, 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) #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @ossl_slh_ht_verify(ptr noundef %0, ptr nocapture noundef readonly %1, ptr noundef %2, ptr noundef %3, i64 noundef %4, i32 noundef %5, ptr nocapture noundef readonly %6) local_unnamed_addr #3 {
  %8 = alloca [32 x i8], align 16
  %9 = alloca [32 x i8], align 16
  %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) #5
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %9) #5
  %13 = getelementptr inbounds i8, ptr %10, i64 160
  %14 = load ptr, ptr %13, align 8, !tbaa !13
  %15 = getelementptr inbounds i8, ptr %14, i64 28
  %16 = load i32, ptr %15, align 4, !tbaa !14
  %17 = getelementptr inbounds i8, ptr %14, i64 16
  %18 = load i32, ptr %17, align 8, !tbaa !17
  %19 = getelementptr inbounds i8, ptr %14, i64 24
  %20 = load i32, ptr %19, align 8, !tbaa !18
  %notmask = shl nsw i32 -1, %16
  %21 = xor i32 %notmask, -1
  %22 = getelementptr inbounds i8, ptr %12, i64 72
  %23 = load ptr, ptr %22, align 8, !tbaa !19
  call void %23(ptr noundef nonnull %8) #5
  %24 = zext i32 %18 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 16 %9, ptr align 1 %1, i64 %24, i1 false)
  %.not33 = icmp eq i32 %20, 0
  br i1 %.not33, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %7
  %25 = getelementptr inbounds i8, ptr %12, i64 8
  %26 = zext nneg i32 %16 to i64
  br label %27

27:                                               ; preds = %.lr.ph, %31
  %.032 = phi i32 [ 0, %.lr.ph ], [ %35, %31 ]
  %.02831 = phi i64 [ %4, %.lr.ph ], [ %34, %31 ]
  %.02930 = phi i32 [ %5, %.lr.ph ], [ %33, %31 ]
  %28 = load ptr, ptr %12, align 8, !tbaa !21
  call void %28(ptr noundef nonnull %8, i32 noundef %.032) #5
  %29 = load ptr, ptr %25, align 8, !tbaa !22
  call void %29(ptr noundef nonnull %8, i64 noundef %.02831) #5
  %30 = call i32 @ossl_slh_xmss_pk_from_sig(ptr noundef nonnull %0, i32 noundef %.02930, ptr noundef %2, ptr noundef nonnull %9, ptr noundef %3, ptr noundef nonnull %8, ptr noundef nonnull %9, i64 noundef 32) #5
  %.not = icmp eq i32 %30, 0
  br i1 %.not, label %.loopexit, label %31

31:                                               ; preds = %27
  %32 = trunc i64 %.02831 to i32
  %33 = and i32 %32, %21
  %34 = lshr i64 %.02831, %26
  %35 = add nuw i32 %.032, 1
  %exitcond.not = icmp eq i32 %35, %20
  br i1 %exitcond.not, label %._crit_edge, label %27, !llvm.loop !23

._crit_edge:                                      ; preds = %31, %7
  %bcmp = call i32 @bcmp(ptr nonnull %9, ptr %6, i64 %24)
  %36 = icmp eq i32 %bcmp, 0
  %37 = zext i1 %36 to i32
  br label %.loopexit

.loopexit:                                        ; preds = %27, %._crit_edge
  %.027 = phi i32 [ %37, %._crit_edge ], [ 0, %27 ]
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %9) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %8) #5
  ret i32 %.027
}

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree 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 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 = { nofree nounwind willreturn memory(argmem: read) }
attributes #5 = { 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 28}
!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 16}
!18 = !{!15, !10, i64 24}
!19 = !{!20, !7, i64 72}
!20 = !{!"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}
!21 = !{!20, !7, i64 0}
!22 = !{!20, !7, i64 8}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}


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