; LLVM IR from guanzhi/GmSSL :: src (sm3_lms)

; 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.SHA256_CTX = type { [8 x i32], i64, [64 x i8], i64 }

@D_LEAF = external hidden constant [2 x i8], align 1
@D_INTR = external hidden constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @sm3_lmots_derive_secrets(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #0

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

declare void @sha256_init(ptr noundef) #2

declare void @sha256_update(ptr noundef, ptr noundef, i64 noundef) #2

declare void @sha256_finish(ptr noundef, ptr noundef) #2

; 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
declare dso_local void @sm3_lmots_secrets_to_public_hash(ptr noundef, i32 noundef, ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @sm3_lms_derive_merkle_tree(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca [4 x i8], align 1
  %12 = alloca %struct.SHA256_CTX, align 8
  %13 = alloca [34 x [32 x i8]], align 16
  %14 = alloca [32 x i8], align 16
  %15 = alloca ptr, align 8
  %16 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %17 = load i32, ptr %7, align 4, !tbaa !9
  %18 = shl i32 1, %17
  store i32 %18, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 112, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 1088, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr %14) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  %19 = load ptr, ptr %8, align 8, !tbaa !5
  %20 = getelementptr inbounds [32 x i8], ptr %19, i64 -1
  store ptr %20, ptr %15, align 8, !tbaa !5
  %21 = load i32, ptr %10, align 4, !tbaa !9
  %22 = mul nsw i32 2, %21
  %23 = sub nsw i32 %22, 1
  store i32 %23, ptr %9, align 4, !tbaa !9
  br label %24

24:                                               ; preds = %88, %4
  %25 = load i32, ptr %9, align 4, !tbaa !9
  %26 = icmp sge i32 %25, 1
  br i1 %26, label %27, label %91

27:                                               ; preds = %24
  %28 = load i32, ptr %9, align 4, !tbaa !9
  %29 = ashr i32 %28, 24
  %30 = trunc i32 %29 to i8
  %31 = getelementptr inbounds [4 x i8], ptr %11, i64 0, i64 0
  store i8 %30, ptr %31, align 1, !tbaa !11
  %32 = load i32, ptr %9, align 4, !tbaa !9
  %33 = ashr i32 %32, 16
  %34 = trunc i32 %33 to i8
  %35 = getelementptr inbounds [4 x i8], ptr %11, i64 0, i64 1
  store i8 %34, ptr %35, align 1, !tbaa !11
  %36 = load i32, ptr %9, align 4, !tbaa !9
  %37 = ashr i32 %36, 8
  %38 = trunc i32 %37 to i8
  %39 = getelementptr inbounds [4 x i8], ptr %11, i64 0, i64 2
  store i8 %38, ptr %39, align 1, !tbaa !11
  %40 = load i32, ptr %9, align 4, !tbaa !9
  %41 = trunc i32 %40 to i8
  %42 = getelementptr inbounds [4 x i8], ptr %11, i64 0, i64 3
  store i8 %41, ptr %42, align 1, !tbaa !11
  %43 = load i32, ptr %9, align 4, !tbaa !9
  %44 = load i32, ptr %10, align 4, !tbaa !9
  %45 = icmp sge i32 %43, %44
  br i1 %45, label %46, label %66

46:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  %47 = load i32, ptr %9, align 4, !tbaa !9
  %48 = load i32, ptr %10, align 4, !tbaa !9
  %49 = sub nsw i32 %47, %48
  store i32 %49, ptr %16, align 4, !tbaa !9
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = load i32, ptr %16, align 4, !tbaa !9
  %53 = getelementptr inbounds [34 x [32 x i8]], ptr %13, i64 0, i64 0
  call void @sm3_lmots_derive_secrets(ptr noundef %50, ptr noundef %51, i32 noundef %52, ptr noundef %53)
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = load i32, ptr %16, align 4, !tbaa !9
  %56 = getelementptr inbounds [34 x [32 x i8]], ptr %13, i64 0, i64 0
  %57 = getelementptr inbounds [32 x i8], ptr %14, i64 0, i64 0
  call void @sm3_lmots_secrets_to_public_hash(ptr noundef %54, i32 noundef %55, ptr noundef %56, ptr noundef %57)
  call void @sha256_init(ptr noundef %12)
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  call void @sha256_update(ptr noundef %12, ptr noundef %58, i64 noundef 16)
  %59 = getelementptr inbounds [4 x i8], ptr %11, i64 0, i64 0
  call void @sha256_update(ptr noundef %12, ptr noundef %59, i64 noundef 4)
  call void @sha256_update(ptr noundef %12, ptr noundef @D_LEAF, i64 noundef 2)
  %60 = getelementptr inbounds [32 x i8], ptr %14, i64 0, i64 0
  call void @sha256_update(ptr noundef %12, ptr noundef %60, i64 noundef 32)
  %61 = load ptr, ptr %15, align 8, !tbaa !5
  %62 = load i32, ptr %9, align 4, !tbaa !9
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [32 x i8], ptr %61, i64 %63
  %65 = getelementptr inbounds [32 x i8], ptr %64, i64 0, i64 0
  call void @sha256_finish(ptr noundef %12, ptr noundef %65)
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  br label %87

66:                                               ; preds = %27
  call void @sha256_init(ptr noundef %12)
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  call void @sha256_update(ptr noundef %12, ptr noundef %67, i64 noundef 16)
  %68 = getelementptr inbounds [4 x i8], ptr %11, i64 0, i64 0
  call void @sha256_update(ptr noundef %12, ptr noundef %68, i64 noundef 4)
  call void @sha256_update(ptr noundef %12, ptr noundef @D_INTR, i64 noundef 2)
  %69 = load ptr, ptr %15, align 8, !tbaa !5
  %70 = load i32, ptr %9, align 4, !tbaa !9
  %71 = mul nsw i32 2, %70
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [32 x i8], ptr %69, i64 %72
  %74 = getelementptr inbounds [32 x i8], ptr %73, i64 0, i64 0
  call void @sha256_update(ptr noundef %12, ptr noundef %74, i64 noundef 32)
  %75 = load ptr, ptr %15, align 8, !tbaa !5
  %76 = load i32, ptr %9, align 4, !tbaa !9
  %77 = mul nsw i32 2, %76
  %78 = add nsw i32 %77, 1
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds [32 x i8], ptr %75, i64 %79
  %81 = getelementptr inbounds [32 x i8], ptr %80, i64 0, i64 0
  call void @sha256_update(ptr noundef %12, ptr noundef %81, i64 noundef 32)
  %82 = load ptr, ptr %15, align 8, !tbaa !5
  %83 = load i32, ptr %9, align 4, !tbaa !9
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds [32 x i8], ptr %82, i64 %84
  %86 = getelementptr inbounds [32 x i8], ptr %85, i64 0, i64 0
  call void @sha256_finish(ptr noundef %12, ptr noundef %86)
  br label %87

87:                                               ; preds = %66, %46
  br label %88

88:                                               ; preds = %87
  %89 = load i32, ptr %9, align 4, !tbaa !9
  %90 = add nsw i32 %89, -1
  store i32 %90, ptr %9, align 4, !tbaa !9
  br label %24, !llvm.loop !12

91:                                               ; preds = %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 1088, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 112, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  ret void
}

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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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.SHA256_CTX = type { [8 x i32], i64, [64 x i8], i64 }

@D_LEAF = external hidden constant [2 x i8], align 1
@D_INTR = external hidden constant [2 x i8], align 1

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

declare void @sha256_init(ptr noundef) local_unnamed_addr #2

declare void @sha256_update(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

declare void @sha256_finish(ptr noundef, ptr 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

; Function Attrs: nounwind uwtable
declare dso_local void @sm3_lmots_secrets_to_public_hash(ptr noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @sm3_lms_derive_merkle_tree(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = alloca [4 x i8], align 1
  %6 = alloca %struct.SHA256_CTX, align 8
  %7 = alloca [34 x [32 x i8]], align 16
  %8 = alloca [32 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #3
  call void @llvm.lifetime.start.p0(i64 112, ptr nonnull %6) #3
  call void @llvm.lifetime.start.p0(i64 1088, ptr nonnull %7) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %8) #3
  %9 = getelementptr inbounds i8, ptr %3, i64 -32
  %10 = shl i32 2, %2
  %11 = icmp sgt i32 %10, 1
  br i1 %11, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %4
  %12 = shl nuw i32 1, %2
  %13 = getelementptr inbounds i8, ptr %5, i64 1
  %14 = getelementptr inbounds i8, ptr %5, i64 2
  %15 = getelementptr inbounds i8, ptr %5, i64 3
  %16 = zext nneg i32 %10 to i64
  %17 = sext i32 %12 to i64
  br label %18

18:                                               ; preds = %.lr.ph, %34
  %indvars.iv = phi i64 [ %16, %.lr.ph ], [ %indvars.iv.next, %34 ]
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %19 = lshr i64 %indvars.iv.next, 24
  %20 = trunc i64 %19 to i8
  store i8 %20, ptr %5, align 1, !tbaa !5
  %21 = lshr i64 %indvars.iv.next, 16
  %22 = trunc i64 %21 to i8
  store i8 %22, ptr %13, align 1, !tbaa !5
  %23 = lshr i64 %indvars.iv.next, 8
  %24 = trunc i64 %23 to i8
  store i8 %24, ptr %14, align 1, !tbaa !5
  %25 = trunc i64 %indvars.iv.next to i8
  store i8 %25, ptr %15, align 1, !tbaa !5
  %.not.not = icmp sgt i64 %indvars.iv, %17
  %26 = getelementptr inbounds [32 x i8], ptr %9, i64 %indvars.iv.next
  br i1 %.not.not, label %27, label %30

27:                                               ; preds = %18
  %28 = trunc i64 %indvars.iv.next to i32
  %29 = sub i32 %28, %12
  call void @sm3_lmots_derive_secrets(ptr noundef %0, ptr noundef %1, i32 noundef %29, ptr noundef nonnull %7)
  call void @sm3_lmots_secrets_to_public_hash(ptr noundef %1, i32 noundef %29, ptr noundef nonnull %7, ptr noundef nonnull %8)
  call void @sha256_init(ptr noundef nonnull %6) #3
  call void @sha256_update(ptr noundef nonnull %6, ptr noundef %1, i64 noundef 16) #3
  call void @sha256_update(ptr noundef nonnull %6, ptr noundef nonnull %5, i64 noundef 4) #3
  call void @sha256_update(ptr noundef nonnull %6, ptr noundef nonnull @D_LEAF, i64 noundef 2) #3
  br label %34

30:                                               ; preds = %18
  call void @sha256_init(ptr noundef nonnull %6) #3
  call void @sha256_update(ptr noundef nonnull %6, ptr noundef %1, i64 noundef 16) #3
  call void @sha256_update(ptr noundef nonnull %6, ptr noundef nonnull %5, i64 noundef 4) #3
  call void @sha256_update(ptr noundef nonnull %6, ptr noundef nonnull @D_INTR, i64 noundef 2) #3
  %31 = shl nuw nsw i64 %indvars.iv.next, 1
  %32 = getelementptr inbounds [32 x i8], ptr %9, i64 %31
  call void @sha256_update(ptr noundef nonnull %6, ptr noundef nonnull %32, i64 noundef 32) #3
  %33 = getelementptr [32 x i8], ptr %3, i64 %31
  br label %34

34:                                               ; preds = %27, %30
  %.sink = phi ptr [ %8, %27 ], [ %33, %30 ]
  call void @sha256_update(ptr noundef nonnull %6, ptr noundef nonnull %.sink, i64 noundef 32) #3
  call void @sha256_finish(ptr noundef nonnull %6, ptr noundef nonnull %26) #3
  %35 = icmp ugt i64 %indvars.iv, 2
  br i1 %35, label %18, label %._crit_edge, !llvm.loop !8

._crit_edge:                                      ; preds = %34, %4
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %8) #3
  call void @llvm.lifetime.end.p0(i64 1088, ptr nonnull %7) #3
  call void @llvm.lifetime.end.p0(i64 112, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #3
  ret void
}

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, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


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