; 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_XMSS_SIGNATURE = type { [4 x i8], [32 x i8], [67 x [32 x i8]], [20 x [32 x i8]] }

@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [1 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [11 x i8], align 1

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

declare i32 @format_print(ptr noundef, i32 noundef, i32 noundef, ptr noundef, ...) #1

declare i32 @format_bytes(ptr noundef, i32 noundef, i32 noundef, ptr noundef, ptr noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @sm3_xmss_signature_print(ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4, i64 noundef %5) #2 {
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca i32, align 4
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store i32 %2, ptr %9, align 4, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !5
  store i64 %5, ptr %12, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %16 = load ptr, ptr %11, align 8, !tbaa !5
  store ptr %16, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = load i32, ptr %8, align 4, !tbaa !9
  %19 = load i32, ptr %9, align 4, !tbaa !9
  %20 = load ptr, ptr %10, align 8, !tbaa !5
  %21 = call i32 (ptr, i32, i32, ptr, ...) @format_print(ptr noundef %17, i32 noundef %18, i32 noundef %19, ptr noundef @.str.2, ptr noundef %20)
  %22 = load i32, ptr %9, align 4, !tbaa !9
  %23 = add nsw i32 %22, 4
  store i32 %23, ptr %9, align 4, !tbaa !9
  %24 = load ptr, ptr %14, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.SM3_XMSS_SIGNATURE, ptr %24, i32 0, i32 0
  %26 = getelementptr inbounds [4 x i8], ptr %25, i64 0, i64 0
  %27 = load i8, ptr %26, align 1, !tbaa !13
  %28 = zext i8 %27 to i32
  %29 = shl i32 %28, 24
  %30 = load ptr, ptr %14, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.SM3_XMSS_SIGNATURE, ptr %30, i32 0, i32 0
  %32 = getelementptr inbounds [4 x i8], ptr %31, i64 0, i64 1
  %33 = load i8, ptr %32, align 1, !tbaa !13
  %34 = zext i8 %33 to i32
  %35 = shl i32 %34, 16
  %36 = or i32 %29, %35
  %37 = load ptr, ptr %14, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.SM3_XMSS_SIGNATURE, ptr %37, i32 0, i32 0
  %39 = getelementptr inbounds [4 x i8], ptr %38, i64 0, i64 2
  %40 = load i8, ptr %39, align 1, !tbaa !13
  %41 = zext i8 %40 to i32
  %42 = shl i32 %41, 8
  %43 = or i32 %36, %42
  %44 = load ptr, ptr %14, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.SM3_XMSS_SIGNATURE, ptr %44, i32 0, i32 0
  %46 = getelementptr inbounds [4 x i8], ptr %45, i64 0, i64 3
  %47 = load i8, ptr %46, align 1, !tbaa !13
  %48 = zext i8 %47 to i32
  %49 = or i32 %43, %48
  store i32 %49, ptr %13, align 4, !tbaa !9
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = load i32, ptr %8, align 4, !tbaa !9
  %52 = load i32, ptr %9, align 4, !tbaa !9
  %53 = load i32, ptr %13, align 4, !tbaa !9
  %54 = call i32 (ptr, i32, i32, ptr, ...) @format_print(ptr noundef %50, i32 noundef %51, i32 noundef %52, ptr noundef @.str.8, i32 noundef %53)
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  %56 = load i32, ptr %8, align 4, !tbaa !9
  %57 = load i32, ptr %9, align 4, !tbaa !9
  %58 = load ptr, ptr %14, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.SM3_XMSS_SIGNATURE, ptr %58, i32 0, i32 1
  %60 = getelementptr inbounds [32 x i8], ptr %59, i64 0, i64 0
  %61 = call i32 @format_bytes(ptr noundef %55, i32 noundef %56, i32 noundef %57, ptr noundef @.str.9, ptr noundef %60, i64 noundef 32)
  %62 = load ptr, ptr %7, align 8, !tbaa !5
  %63 = load i32, ptr %8, align 4, !tbaa !9
  %64 = load i32, ptr %9, align 4, !tbaa !9
  %65 = call i32 (ptr, i32, i32, ptr, ...) @format_print(ptr noundef %62, i32 noundef %63, i32 noundef %64, ptr noundef @.str.10)
  store i32 0, ptr %15, align 4, !tbaa !9
  br label %66

66:                                               ; preds = %85, %6
  %67 = load i32, ptr %15, align 4, !tbaa !9
  %68 = icmp slt i32 %67, 67
  br i1 %68, label %69, label %88

69:                                               ; preds = %66
  %70 = load ptr, ptr %7, align 8, !tbaa !5
  %71 = load i32, ptr %8, align 4, !tbaa !9
  %72 = load i32, ptr %9, align 4, !tbaa !9
  %73 = add nsw i32 %72, 4
  %74 = load i32, ptr %15, align 4, !tbaa !9
  %75 = call i32 (ptr, i32, i32, ptr, ...) @format_print(ptr noundef %70, i32 noundef %71, i32 noundef %73, ptr noundef @.str.11, i32 noundef %74)
  %76 = load ptr, ptr %7, align 8, !tbaa !5
  %77 = load i32, ptr %8, align 4, !tbaa !9
  %78 = load ptr, ptr %14, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.SM3_XMSS_SIGNATURE, ptr %78, i32 0, i32 2
  %80 = load i32, ptr %15, align 4, !tbaa !9
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds [67 x [32 x i8]], ptr %79, i64 0, i64 %81
  %83 = getelementptr inbounds [32 x i8], ptr %82, i64 0, i64 0
  %84 = call i32 @format_bytes(ptr noundef %76, i32 noundef %77, i32 noundef 0, ptr noundef @.str.12, ptr noundef %83, i64 noundef 32)
  br label %85

85:                                               ; preds = %69
  %86 = load i32, ptr %15, align 4, !tbaa !9
  %87 = add nsw i32 %86, 1
  store i32 %87, ptr %15, align 4, !tbaa !9
  br label %66, !llvm.loop !14

88:                                               ; preds = %66
  %89 = load ptr, ptr %7, align 8, !tbaa !5
  %90 = load i32, ptr %8, align 4, !tbaa !9
  %91 = load i32, ptr %9, align 4, !tbaa !9
  %92 = call i32 (ptr, i32, i32, ptr, ...) @format_print(ptr noundef %89, i32 noundef %90, i32 noundef %91, ptr noundef @.str.13)
  %93 = load i64, ptr %12, align 8, !tbaa !11
  %94 = sub i64 %93, 2180
  store i64 %94, ptr %12, align 8, !tbaa !11
  store i32 0, ptr %15, align 4, !tbaa !9
  br label %95

95:                                               ; preds = %121, %88
  %96 = load i32, ptr %15, align 4, !tbaa !9
  %97 = icmp slt i32 %96, 20
  br i1 %97, label %98, label %101

98:                                               ; preds = %95
  %99 = load i64, ptr %12, align 8, !tbaa !11
  %100 = icmp uge i64 %99, 32
  br label %101

101:                                              ; preds = %98, %95
  %102 = phi i1 [ false, %95 ], [ %100, %98 ]
  br i1 %102, label %103, label %124

103:                                              ; preds = %101
  %104 = load ptr, ptr %7, align 8, !tbaa !5
  %105 = load i32, ptr %8, align 4, !tbaa !9
  %106 = load i32, ptr %9, align 4, !tbaa !9
  %107 = add nsw i32 %106, 4
  %108 = load i32, ptr %15, align 4, !tbaa !9
  %109 = call i32 (ptr, i32, i32, ptr, ...) @format_print(ptr noundef %104, i32 noundef %105, i32 noundef %107, ptr noundef @.str.11, i32 noundef %108)
  %110 = load ptr, ptr %7, align 8, !tbaa !5
  %111 = load i32, ptr %8, align 4, !tbaa !9
  %112 = load ptr, ptr %14, align 8, !tbaa !5
  %113 = getelementptr inbounds %struct.SM3_XMSS_SIGNATURE, ptr %112, i32 0, i32 3
  %114 = load i32, ptr %15, align 4, !tbaa !9
  %115 = sext i32 %114 to i64
  %116 = getelementptr inbounds [20 x [32 x i8]], ptr %113, i64 0, i64 %115
  %117 = getelementptr inbounds [32 x i8], ptr %116, i64 0, i64 0
  %118 = call i32 @format_bytes(ptr noundef %110, i32 noundef %111, i32 noundef 0, ptr noundef @.str.12, ptr noundef %117, i64 noundef 32)
  %119 = load i64, ptr %12, align 8, !tbaa !11
  %120 = sub i64 %119, 32
  store i64 %120, ptr %12, align 8, !tbaa !11
  br label %121

121:                                              ; preds = %103
  %122 = load i32, ptr %15, align 4, !tbaa !9
  %123 = add nsw i32 %122, 1
  store i32 %123, ptr %15, align 4, !tbaa !9
  br label %95, !llvm.loop !16

124:                                              ; preds = %101
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  ret i32 1
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 #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 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


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

@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [1 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [11 x i8], align 1

declare i32 @format_print(ptr noundef, i32 noundef, i32 noundef, ptr noundef, ...) local_unnamed_addr #0

declare i32 @format_bytes(ptr noundef, i32 noundef, i32 noundef, ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @sm3_xmss_signature_print(ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4, i64 noundef %5) local_unnamed_addr #1 {
  %7 = tail call i32 (ptr, i32, i32, ptr, ...) @format_print(ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef nonnull @.str.2, ptr noundef %3) #3
  %8 = add nsw i32 %2, 4
  %9 = load i8, ptr %4, align 1, !tbaa !5
  %10 = zext i8 %9 to i32
  %11 = shl nuw i32 %10, 24
  %12 = getelementptr inbounds i8, ptr %4, i64 1
  %13 = load i8, ptr %12, align 1, !tbaa !5
  %14 = zext i8 %13 to i32
  %15 = shl nuw nsw i32 %14, 16
  %16 = or disjoint i32 %15, %11
  %17 = getelementptr inbounds i8, ptr %4, i64 2
  %18 = load i8, ptr %17, align 1, !tbaa !5
  %19 = zext i8 %18 to i32
  %20 = shl nuw nsw i32 %19, 8
  %21 = or disjoint i32 %16, %20
  %22 = getelementptr inbounds i8, ptr %4, i64 3
  %23 = load i8, ptr %22, align 1, !tbaa !5
  %24 = zext i8 %23 to i32
  %25 = or disjoint i32 %21, %24
  %26 = tail call i32 (ptr, i32, i32, ptr, ...) @format_print(ptr noundef %0, i32 noundef %1, i32 noundef %8, ptr noundef nonnull @.str.8, i32 noundef %25) #3
  %27 = getelementptr inbounds i8, ptr %4, i64 4
  %28 = tail call i32 @format_bytes(ptr noundef %0, i32 noundef %1, i32 noundef %8, ptr noundef nonnull @.str.9, ptr noundef nonnull %27, i64 noundef 32) #3
  %29 = tail call i32 (ptr, i32, i32, ptr, ...) @format_print(ptr noundef %0, i32 noundef %1, i32 noundef %8, ptr noundef nonnull @.str.10) #3
  %30 = add nsw i32 %2, 8
  %31 = getelementptr inbounds i8, ptr %4, i64 36
  br label %32

32:                                               ; preds = %6, %32
  %indvars.iv = phi i64 [ 0, %6 ], [ %indvars.iv.next, %32 ]
  %33 = trunc nuw nsw i64 %indvars.iv to i32
  %34 = tail call i32 (ptr, i32, i32, ptr, ...) @format_print(ptr noundef %0, i32 noundef %1, i32 noundef %30, ptr noundef nonnull @.str.11, i32 noundef %33) #3
  %35 = getelementptr inbounds [67 x [32 x i8]], ptr %31, i64 0, i64 %indvars.iv
  %36 = tail call i32 @format_bytes(ptr noundef %0, i32 noundef %1, i32 noundef 0, ptr noundef nonnull @.str.12, ptr noundef nonnull %35, i64 noundef 32) #3
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 67
  br i1 %exitcond.not, label %37, label %32, !llvm.loop !8

37:                                               ; preds = %32
  %38 = tail call i32 (ptr, i32, i32, ptr, ...) @format_print(ptr noundef %0, i32 noundef %1, i32 noundef %8, ptr noundef nonnull @.str.13) #3
  %39 = add i64 %5, -2212
  %40 = icmp ult i64 %39, -32
  br i1 %40, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %37
  %41 = getelementptr inbounds i8, ptr %4, i64 2180
  %42 = add i64 %5, -2212
  %43 = lshr i64 %42, 5
  %umin = tail call i64 @llvm.umin.i64(i64 %43, i64 19)
  br label %44

44:                                               ; preds = %.lr.ph, %44
  %indvars.iv51 = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next52, %44 ]
  %45 = trunc nuw nsw i64 %indvars.iv51 to i32
  %46 = tail call i32 (ptr, i32, i32, ptr, ...) @format_print(ptr noundef %0, i32 noundef %1, i32 noundef %30, ptr noundef nonnull @.str.11, i32 noundef %45) #3
  %47 = getelementptr inbounds [20 x [32 x i8]], ptr %41, i64 0, i64 %indvars.iv51
  %48 = tail call i32 @format_bytes(ptr noundef %0, i32 noundef %1, i32 noundef 0, ptr noundef nonnull @.str.12, ptr noundef nonnull %47, i64 noundef 32) #3
  %indvars.iv.next52 = add nuw nsw i64 %indvars.iv51, 1
  %exitcond54.not = icmp eq i64 %indvars.iv51, %umin
  br i1 %exitcond54.not, label %._crit_edge, label %44, !llvm.loop !10

._crit_edge:                                      ; preds = %44, %37
  ret i32 1
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umin.i64(i64, i64) #2

attributes #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 = { 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 #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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"}
!10 = distinct !{!10, !9}


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