; 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 }

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

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

36:                                               ; preds = %101, %5
  %37 = load i32, ptr %16, align 4, !tbaa !9
  %38 = icmp slt i32 %37, 34
  br i1 %38, label %39, label %104

39:                                               ; preds = %36
  %40 = load i32, ptr %16, align 4, !tbaa !9
  %41 = ashr i32 %40, 8
  %42 = trunc i32 %41 to i8
  %43 = getelementptr inbounds [2 x i8], ptr %14, i64 0, i64 0
  store i8 %42, ptr %43, align 1, !tbaa !11
  %44 = load i32, ptr %16, align 4, !tbaa !9
  %45 = trunc i32 %44 to i8
  %46 = getelementptr inbounds [2 x i8], ptr %14, i64 0, i64 1
  store i8 %45, ptr %46, align 1, !tbaa !11
  %47 = load ptr, ptr %10, align 8, !tbaa !5
  %48 = load i32, ptr %16, align 4, !tbaa !9
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [32 x i8], ptr %47, i64 %49
  %51 = getelementptr inbounds [32 x i8], ptr %50, i64 0, i64 0
  %52 = load ptr, ptr %9, align 8, !tbaa !5
  %53 = load i32, ptr %16, align 4, !tbaa !9
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [32 x i8], ptr %52, i64 %54
  %56 = getelementptr inbounds [32 x i8], ptr %55, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %51, ptr align 1 %56, i64 32, i1 false)
  %57 = load i32, ptr %16, align 4, !tbaa !9
  %58 = icmp slt i32 %57, 32
  br i1 %58, label %59, label %66

59:                                               ; preds = %39
  %60 = load ptr, ptr %8, align 8, !tbaa !5
  %61 = load i32, ptr %16, align 4, !tbaa !9
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds i8, ptr %60, i64 %62
  %64 = load i8, ptr %63, align 1, !tbaa !11
  %65 = zext i8 %64 to i32
  br label %73

66:                                               ; preds = %39
  %67 = load i32, ptr %16, align 4, !tbaa !9
  %68 = sub nsw i32 %67, 32
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [2 x i8], ptr %12, i64 0, i64 %69
  %71 = load i8, ptr %70, align 1, !tbaa !11
  %72 = zext i8 %71 to i32
  br label %73

73:                                               ; preds = %66, %59
  %74 = phi i32 [ %65, %59 ], [ %72, %66 ]
  store i32 %74, ptr %18, align 4, !tbaa !9
  store i32 0, ptr %17, align 4, !tbaa !9
  br label %75

75:                                               ; preds = %97, %73
  %76 = load i32, ptr %17, align 4, !tbaa !9
  %77 = load i32, ptr %18, align 4, !tbaa !9
  %78 = icmp slt i32 %76, %77
  br i1 %78, label %79, label %100

79:                                               ; preds = %75
  %80 = load i32, ptr %17, align 4, !tbaa !9
  %81 = trunc i32 %80 to i8
  %82 = getelementptr inbounds [1 x i8], ptr %15, i64 0, i64 0
  store i8 %81, ptr %82, align 1, !tbaa !11
  call void @sha256_init(ptr noundef %11)
  %83 = load ptr, ptr %6, align 8, !tbaa !5
  call void @sha256_update(ptr noundef %11, ptr noundef %83, i64 noundef 16)
  %84 = getelementptr inbounds [4 x i8], ptr %13, i64 0, i64 0
  call void @sha256_update(ptr noundef %11, ptr noundef %84, i64 noundef 4)
  %85 = getelementptr inbounds [2 x i8], ptr %14, i64 0, i64 0
  call void @sha256_update(ptr noundef %11, ptr noundef %85, i64 noundef 2)
  %86 = getelementptr inbounds [1 x i8], ptr %15, i64 0, i64 0
  call void @sha256_update(ptr noundef %11, ptr noundef %86, i64 noundef 1)
  %87 = load ptr, ptr %10, align 8, !tbaa !5
  %88 = load i32, ptr %16, align 4, !tbaa !9
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds [32 x i8], ptr %87, i64 %89
  %91 = getelementptr inbounds [32 x i8], ptr %90, i64 0, i64 0
  call void @sha256_update(ptr noundef %11, ptr noundef %91, i64 noundef 32)
  %92 = load ptr, ptr %10, align 8, !tbaa !5
  %93 = load i32, ptr %16, align 4, !tbaa !9
  %94 = sext i32 %93 to i64
  %95 = getelementptr inbounds [32 x i8], ptr %92, i64 %94
  %96 = getelementptr inbounds [32 x i8], ptr %95, i64 0, i64 0
  call void @sha256_finish(ptr noundef %11, ptr noundef %96)
  br label %97

97:                                               ; preds = %79
  %98 = load i32, ptr %17, align 4, !tbaa !9
  %99 = add nsw i32 %98, 1
  store i32 %99, ptr %17, align 4, !tbaa !9
  br label %75, !llvm.loop !12

100:                                              ; preds = %75
  br label %101

101:                                              ; preds = %100
  %102 = load i32, ptr %16, align 4, !tbaa !9
  %103 = add nsw i32 %102, 1
  store i32 %103, ptr %16, align 4, !tbaa !9
  br label %36, !llvm.loop !14

104:                                              ; preds = %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 2, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 2, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 112, ptr %11) #4
  ret void
}

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

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 }

!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"}
!14 = distinct !{!14, !13}


; 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 }

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

; Function Attrs: nounwind uwtable
define dso_local void @sm3_lmots_compute_signature(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr nocapture noundef readonly %3, ptr noundef %4) local_unnamed_addr #3 {
  %6 = alloca %struct.SHA256_CTX, align 8
  %7 = alloca [2 x i8], align 1
  %8 = alloca [4 x i8], align 1
  %9 = alloca [2 x i8], align 1
  %10 = alloca [1 x i8], align 1
  call void @llvm.lifetime.start.p0(i64 112, ptr nonnull %6) #4
  call void @llvm.lifetime.start.p0(i64 2, ptr nonnull %7) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %8) #4
  call void @llvm.lifetime.start.p0(i64 2, ptr nonnull %9) #4
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %10) #4
  call void @winternitz_checksum(ptr noundef %2, ptr noundef nonnull %7)
  %11 = lshr i32 %1, 24
  %12 = trunc nuw i32 %11 to i8
  store i8 %12, ptr %8, align 1, !tbaa !5
  %13 = lshr i32 %1, 16
  %14 = trunc i32 %13 to i8
  %15 = getelementptr inbounds i8, ptr %8, i64 1
  store i8 %14, ptr %15, align 1, !tbaa !5
  %16 = lshr i32 %1, 8
  %17 = trunc i32 %16 to i8
  %18 = getelementptr inbounds i8, ptr %8, i64 2
  store i8 %17, ptr %18, align 1, !tbaa !5
  %19 = trunc i32 %1 to i8
  %20 = getelementptr inbounds i8, ptr %8, i64 3
  store i8 %19, ptr %20, align 1, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %9, i64 1
  br label %22

22:                                               ; preds = %5, %._crit_edge
  %indvars.iv = phi i64 [ 0, %5 ], [ %indvars.iv.next, %._crit_edge ]
  store i8 0, ptr %9, align 1, !tbaa !5
  %23 = trunc i64 %indvars.iv to i8
  store i8 %23, ptr %21, align 1, !tbaa !5
  %24 = getelementptr inbounds [32 x i8], ptr %4, i64 %indvars.iv
  %25 = getelementptr inbounds [32 x i8], ptr %3, i64 %indvars.iv
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(32) %24, ptr noundef nonnull align 1 dereferenceable(32) %25, i64 32, i1 false)
  %26 = icmp ult i64 %indvars.iv, 32
  %27 = getelementptr inbounds i8, ptr %2, i64 %indvars.iv
  %28 = add nsw i64 %indvars.iv, -32
  %29 = getelementptr inbounds [2 x i8], ptr %7, i64 0, i64 %28
  %.in.in = select i1 %26, ptr %27, ptr %29
  %.in = load i8, ptr %.in.in, align 1, !tbaa !5
  %30 = zext i8 %.in to i32
  %.not = icmp eq i8 %.in, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %22, %.lr.ph
  %.02526 = phi i32 [ %32, %.lr.ph ], [ 0, %22 ]
  %31 = trunc i32 %.02526 to i8
  store i8 %31, ptr %10, align 1, !tbaa !5
  call void @sha256_init(ptr noundef nonnull %6) #4
  call void @sha256_update(ptr noundef nonnull %6, ptr noundef %0, i64 noundef 16) #4
  call void @sha256_update(ptr noundef nonnull %6, ptr noundef nonnull %8, i64 noundef 4) #4
  call void @sha256_update(ptr noundef nonnull %6, ptr noundef nonnull %9, i64 noundef 2) #4
  call void @sha256_update(ptr noundef nonnull %6, ptr noundef nonnull %10, i64 noundef 1) #4
  call void @sha256_update(ptr noundef nonnull %6, ptr noundef %24, i64 noundef 32) #4
  call void @sha256_finish(ptr noundef nonnull %6, ptr noundef %24) #4
  %32 = add nuw nsw i32 %.02526, 1
  %exitcond.not = icmp eq i32 %32, %30
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !8

._crit_edge:                                      ; preds = %.lr.ph, %22
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond29.not = icmp eq i64 %indvars.iv.next, 34
  br i1 %exitcond29.not, label %33, label %22, !llvm.loop !10

33:                                               ; preds = %._crit_edge
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %10) #4
  call void @llvm.lifetime.end.p0(i64 2, ptr nonnull %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %8) #4
  call void @llvm.lifetime.end.p0(i64 2, ptr nonnull %7) #4
  call void @llvm.lifetime.end.p0(i64 112, ptr nonnull %6) #4
  ret void
}

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

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 = { 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"}
!10 = distinct !{!10, !9}


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