; LLVM IR from guanzhi/GmSSL :: src (sm3_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.SM3_CTX = type { [8 x i32], i64, [64 x i8], 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 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
declare dso_local void @sm3_wots_sig_to_pk(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden void @hash256_prf_init(ptr noundef, ptr noundef) #2

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

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

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

; Function Attrs: nounwind uwtable
declare hidden void @build_ltree(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @sm3_xmss_sig_to_root(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, i32 noundef %5, ptr noundef %6, ptr noundef %7) #2 {
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca %struct.SM3_CTX, align 8
  %18 = alloca [32 x i8], align 16
  %19 = alloca [67 x [32 x i8]], align 16
  %20 = alloca ptr, align 8
  %21 = alloca i32, align 4
  %22 = alloca i32, align 4
  store ptr %0, ptr %9, align 8, !tbaa !5
  store i32 %1, ptr %10, align 4, !tbaa !9
  store ptr %2, ptr %11, align 8, !tbaa !5
  store ptr %3, ptr %12, align 8, !tbaa !5
  store ptr %4, ptr %13, align 8, !tbaa !5
  store i32 %5, ptr %14, align 4, !tbaa !9
  store ptr %6, ptr %15, align 8, !tbaa !5
  store ptr %7, ptr %16, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 112, ptr %17) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr %18) #3
  call void @llvm.lifetime.start.p0(i64 2144, ptr %19) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #3
  %23 = load ptr, ptr %16, align 8, !tbaa !5
  store ptr %23, ptr %20, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #3
  %24 = load ptr, ptr %12, align 8, !tbaa !5
  call void @hash256_prf_init(ptr noundef %17, ptr noundef %24)
  %25 = getelementptr inbounds [32 x i8], ptr %18, i64 0, i64 0
  %26 = load ptr, ptr %13, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %25, ptr align 1 %26, i64 32, i1 false)
  %27 = getelementptr inbounds [32 x i8], ptr %18, i64 0, i64 0
  call void @adrs_set_type(ptr noundef %27, i32 noundef 0)
  %28 = getelementptr inbounds [32 x i8], ptr %18, i64 0, i64 0
  %29 = load i32, ptr %10, align 4, !tbaa !9
  call void @adrs_set_ots_address(ptr noundef %28, i32 noundef %29)
  %30 = load ptr, ptr %9, align 8, !tbaa !5
  %31 = load ptr, ptr %15, align 8, !tbaa !5
  %32 = getelementptr inbounds [32 x i8], ptr %18, i64 0, i64 0
  %33 = getelementptr inbounds [67 x [32 x i8]], ptr %19, i64 0, i64 0
  call void @sm3_wots_sig_to_pk(ptr noundef %30, ptr noundef %31, ptr noundef %17, ptr noundef %32, ptr noundef %33)
  %34 = getelementptr inbounds [32 x i8], ptr %18, i64 0, i64 0
  call void @adrs_set_type(ptr noundef %34, i32 noundef 1)
  %35 = getelementptr inbounds [32 x i8], ptr %18, i64 0, i64 0
  %36 = load i32, ptr %10, align 4, !tbaa !9
  call void @adrs_set_ltree_address(ptr noundef %35, i32 noundef %36)
  %37 = getelementptr inbounds [67 x [32 x i8]], ptr %19, i64 0, i64 0
  %38 = getelementptr inbounds [32 x i8], ptr %18, i64 0, i64 0
  %39 = load ptr, ptr %20, align 8, !tbaa !5
  call void @build_ltree(ptr noundef %37, ptr noundef %17, ptr noundef %38, ptr noundef %39)
  %40 = getelementptr inbounds [32 x i8], ptr %18, i64 0, i64 0
  call void @adrs_set_type(ptr noundef %40, i32 noundef 2)
  %41 = getelementptr inbounds [32 x i8], ptr %18, i64 0, i64 0
  %42 = load i32, ptr %10, align 4, !tbaa !9
  call void @adrs_set_tree_index(ptr noundef %41, i32 noundef %42)
  store i32 0, ptr %21, align 4, !tbaa !9
  br label %43

43:                                               ; preds = %77, %8
  %44 = load i32, ptr %21, align 4, !tbaa !9
  %45 = load i32, ptr %14, align 4, !tbaa !9
  %46 = icmp slt i32 %44, %45
  br i1 %46, label %47, label %80

47:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 4, ptr %22) #3
  %48 = load i32, ptr %10, align 4, !tbaa !9
  %49 = and i32 %48, 1
  store i32 %49, ptr %22, align 4, !tbaa !9
  %50 = load i32, ptr %10, align 4, !tbaa !9
  %51 = ashr i32 %50, 1
  store i32 %51, ptr %10, align 4, !tbaa !9
  %52 = getelementptr inbounds [32 x i8], ptr %18, i64 0, i64 0
  %53 = load i32, ptr %21, align 4, !tbaa !9
  call void @adrs_set_tree_height(ptr noundef %52, i32 noundef %53)
  %54 = getelementptr inbounds [32 x i8], ptr %18, i64 0, i64 0
  %55 = load i32, ptr %10, align 4, !tbaa !9
  call void @adrs_set_tree_index(ptr noundef %54, i32 noundef %55)
  %56 = load i32, ptr %22, align 4, !tbaa !9
  %57 = icmp ne i32 %56, 0
  br i1 %57, label %58, label %67

58:                                               ; preds = %47
  %59 = load ptr, ptr %11, align 8, !tbaa !5
  %60 = load i32, ptr %21, align 4, !tbaa !9
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [32 x i8], ptr %59, i64 %61
  %63 = getelementptr inbounds [32 x i8], ptr %62, i64 0, i64 0
  %64 = load ptr, ptr %20, align 8, !tbaa !5
  %65 = getelementptr inbounds [32 x i8], ptr %18, i64 0, i64 0
  %66 = load ptr, ptr %20, align 8, !tbaa !5
  call void @randomized_hash(ptr noundef %63, ptr noundef %64, ptr noundef %17, ptr noundef %65, ptr noundef %66)
  br label %76

67:                                               ; preds = %47
  %68 = load ptr, ptr %20, align 8, !tbaa !5
  %69 = load ptr, ptr %11, align 8, !tbaa !5
  %70 = load i32, ptr %21, align 4, !tbaa !9
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [32 x i8], ptr %69, i64 %71
  %73 = getelementptr inbounds [32 x i8], ptr %72, i64 0, i64 0
  %74 = getelementptr inbounds [32 x i8], ptr %18, i64 0, i64 0
  %75 = load ptr, ptr %20, align 8, !tbaa !5
  call void @randomized_hash(ptr noundef %68, ptr noundef %73, ptr noundef %17, ptr noundef %74, ptr noundef %75)
  br label %76

76:                                               ; preds = %67, %58
  call void @llvm.lifetime.end.p0(i64 4, ptr %22) #3
  br label %77

77:                                               ; preds = %76
  %78 = load i32, ptr %21, align 4, !tbaa !9
  %79 = add nsw i32 %78, 1
  store i32 %79, ptr %21, align 4, !tbaa !9
  br label %43, !llvm.loop !11

80:                                               ; preds = %43
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #3
  call void @llvm.lifetime.end.p0(i64 2144, ptr %19) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr %18) #3
  call void @llvm.lifetime.end.p0(i64 112, ptr %17) #3
  ret void
}

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

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

; Function Attrs: nounwind uwtable
declare hidden void @randomized_hash(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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, !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 = distinct !{!11, !12}
!12 = !{!"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"

%struct.SM3_CTX = type { [8 x i32], i64, [64 x i8], i64 }

; 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

; 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
declare dso_local void @sm3_wots_sig_to_pk(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

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

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @sm3_xmss_sig_to_root(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3, ptr nocapture noundef readonly %4, i32 noundef %5, ptr noundef %6, ptr noundef %7) local_unnamed_addr #2 {
  %9 = alloca %struct.SM3_CTX, align 8
  %10 = alloca [32 x i8], align 16
  %11 = alloca [67 x [32 x i8]], align 16
  call void @llvm.lifetime.start.p0(i64 112, ptr nonnull %9) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %10) #3
  call void @llvm.lifetime.start.p0(i64 2144, ptr nonnull %11) #3
  call void @hash256_prf_init(ptr noundef nonnull %9, ptr noundef %3)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(32) %10, ptr noundef nonnull align 1 dereferenceable(32) %4, i64 32, i1 false)
  call void @adrs_set_type(ptr noundef nonnull %10, i32 noundef 0)
  call void @adrs_set_ots_address(ptr noundef nonnull %10, i32 noundef %1)
  call void @sm3_wots_sig_to_pk(ptr noundef %0, ptr noundef %6, ptr noundef nonnull %9, ptr noundef nonnull %10, ptr noundef nonnull %11)
  call void @adrs_set_type(ptr noundef nonnull %10, i32 noundef 1)
  call void @adrs_set_ltree_address(ptr noundef nonnull %10, i32 noundef %1)
  call void @build_ltree(ptr noundef nonnull %11, ptr noundef nonnull %9, ptr noundef nonnull %10, ptr noundef %7)
  call void @adrs_set_type(ptr noundef nonnull %10, i32 noundef 2)
  call void @adrs_set_tree_index(ptr noundef nonnull %10, i32 noundef %1)
  %12 = icmp sgt i32 %5, 0
  br i1 %12, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %8
  %wide.trip.count = zext nneg i32 %5 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %19
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %19 ]
  %.026 = phi i32 [ %1, %.lr.ph.preheader ], [ %14, %19 ]
  %13 = and i32 %.026, 1
  %14 = ashr i32 %.026, 1
  %15 = trunc nuw nsw i64 %indvars.iv to i32
  call void @adrs_set_tree_height(ptr noundef nonnull %10, i32 noundef %15)
  call void @adrs_set_tree_index(ptr noundef nonnull %10, i32 noundef %14)
  %.not = icmp eq i32 %13, 0
  %16 = getelementptr inbounds [32 x i8], ptr %2, i64 %indvars.iv
  br i1 %.not, label %18, label %17

17:                                               ; preds = %.lr.ph
  call void @randomized_hash(ptr noundef %16, ptr noundef %7, ptr noundef nonnull %9, ptr noundef nonnull %10, ptr noundef %7)
  br label %19

18:                                               ; preds = %.lr.ph
  call void @randomized_hash(ptr noundef %7, ptr noundef %16, ptr noundef nonnull %9, ptr noundef nonnull %10, ptr noundef %7)
  br label %19

19:                                               ; preds = %18, %17
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !5

._crit_edge:                                      ; preds = %19, %8
  call void @llvm.lifetime.end.p0(i64 2144, ptr nonnull %11) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %10) #3
  call void @llvm.lifetime.end.p0(i64 112, ptr nonnull %9) #3
  ret void
}

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

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

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


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