; 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_SIGN_CTX = type { [32 x i8], %struct.SM3_CTX }
%struct.SM3_CTX = type { [8 x i32], i64, [64 x i8], i64 }
%struct.SM3_XMSS_KEY = type { i32, [32 x i8], [32 x i8], [32 x i8], [32 x i8], i32, ptr }
%struct.SM3_XMSS_SIGNATURE = type { [4 x i8], [32 x i8], [67 x [32 x i8]], [20 x [32 x i8]] }

; 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 @sm3_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: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @sm3_xmss_key_get_height(ptr noundef, ptr noundef) #4

; Function Attrs: nounwind uwtable
define dso_local i32 @sm3_xmss_sign_finish(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #4 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca [32 x i8], align 16
  %11 = alloca [32 x i8], align 16
  %12 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %13 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %13, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 32, ptr %10) #5
  call void @llvm.memset.p0.i64(ptr align 16 %10, i8 0, i64 32, i1 false)
  call void @llvm.lifetime.start.p0(i64 32, ptr %11) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.SM3_XMSS_SIGN_CTX, ptr %14, i32 0, i32 1
  %16 = getelementptr inbounds [32 x i8], ptr %11, i64 0, i64 0
  call void @sm3_finish(ptr noundef %15, ptr noundef %16)
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = call i32 @sm3_xmss_key_get_height(ptr noundef %17, ptr noundef %12)
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.SM3_XMSS_KEY, ptr %19, i32 0, i32 3
  %21 = getelementptr inbounds [32 x i8], ptr %20, i64 0, i64 0
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.SM3_XMSS_KEY, ptr %22, i32 0, i32 5
  %24 = load i32, ptr %23, align 4, !tbaa !9
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.SM3_XMSS_KEY, ptr %25, i32 0, i32 1
  %27 = getelementptr inbounds [32 x i8], ptr %26, i64 0, i64 0
  %28 = getelementptr inbounds [32 x i8], ptr %10, i64 0, i64 0
  %29 = load i32, ptr %12, align 4, !tbaa !12
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.SM3_XMSS_KEY, ptr %30, i32 0, i32 6
  %32 = load ptr, ptr %31, align 8, !tbaa !13
  %33 = getelementptr inbounds [32 x i8], ptr %11, i64 0, i64 0
  %34 = load ptr, ptr %9, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.SM3_XMSS_SIGNATURE, ptr %34, i32 0, i32 2
  %36 = getelementptr inbounds [67 x [32 x i8]], ptr %35, i64 0, i64 0
  %37 = load ptr, ptr %9, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.SM3_XMSS_SIGNATURE, ptr %37, i32 0, i32 3
  %39 = getelementptr inbounds [20 x [32 x i8]], ptr %38, i64 0, i64 0
  call void @sm3_xmss_do_sign(ptr noundef %21, i32 noundef %24, ptr noundef %27, ptr noundef %28, i32 noundef %29, ptr noundef %32, ptr noundef %33, ptr noundef %36, ptr noundef %39)
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.SM3_XMSS_KEY, ptr %40, i32 0, i32 5
  %42 = load i32, ptr %41, align 4, !tbaa !9
  %43 = lshr i32 %42, 24
  %44 = trunc i32 %43 to i8
  %45 = load ptr, ptr %9, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.SM3_XMSS_SIGNATURE, ptr %45, i32 0, i32 0
  %47 = getelementptr inbounds [4 x i8], ptr %46, i64 0, i64 0
  store i8 %44, ptr %47, align 1, !tbaa !14
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.SM3_XMSS_KEY, ptr %48, i32 0, i32 5
  %50 = load i32, ptr %49, align 4, !tbaa !9
  %51 = lshr i32 %50, 16
  %52 = trunc i32 %51 to i8
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.SM3_XMSS_SIGNATURE, ptr %53, i32 0, i32 0
  %55 = getelementptr inbounds [4 x i8], ptr %54, i64 0, i64 1
  store i8 %52, ptr %55, align 1, !tbaa !14
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.SM3_XMSS_KEY, ptr %56, i32 0, i32 5
  %58 = load i32, ptr %57, align 4, !tbaa !9
  %59 = lshr i32 %58, 8
  %60 = trunc i32 %59 to i8
  %61 = load ptr, ptr %9, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.SM3_XMSS_SIGNATURE, ptr %61, i32 0, i32 0
  %63 = getelementptr inbounds [4 x i8], ptr %62, i64 0, i64 2
  store i8 %60, ptr %63, align 1, !tbaa !14
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.SM3_XMSS_KEY, ptr %64, i32 0, i32 5
  %66 = load i32, ptr %65, align 4, !tbaa !9
  %67 = trunc i32 %66 to i8
  %68 = load ptr, ptr %9, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.SM3_XMSS_SIGNATURE, ptr %68, i32 0, i32 0
  %70 = getelementptr inbounds [4 x i8], ptr %69, i64 0, i64 3
  store i8 %67, ptr %70, align 1, !tbaa !14
  %71 = load ptr, ptr %9, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.SM3_XMSS_SIGNATURE, ptr %71, i32 0, i32 1
  %73 = getelementptr inbounds [32 x i8], ptr %72, i64 0, i64 0
  %74 = load ptr, ptr %5, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.SM3_XMSS_SIGN_CTX, ptr %74, i32 0, i32 0
  %76 = getelementptr inbounds [32 x i8], ptr %75, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %73, ptr align 8 %76, i64 32, i1 false)
  %77 = load i32, ptr %12, align 4, !tbaa !12
  %78 = add i32 68, %77
  %79 = mul i32 32, %78
  %80 = add i32 4, %79
  %81 = zext i32 %80 to i64
  %82 = load ptr, ptr %8, align 8, !tbaa !5
  store i64 %81, ptr %82, align 8, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  ret i32 1
}

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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 #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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 132}
!10 = !{!"", !11, i64 0, !7, i64 4, !7, i64 36, !7, i64 68, !7, i64 100, !11, i64 132, !6, i64 136}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !6, i64 136}
!14 = !{!7, !7, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"long", !7, i64 0}


; 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 void @sm3_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: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @sm3_xmss_key_get_height(ptr noundef, ptr noundef) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @sm3_xmss_sign_finish(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #4 {
  %5 = alloca [32 x i8], align 16
  %6 = alloca [32 x i8], align 16
  %7 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %5) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(32) %5, i8 0, i64 32, i1 false)
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %6) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %7) #5
  %8 = getelementptr inbounds i8, ptr %0, i64 32
  call void @sm3_finish(ptr noundef nonnull %8, ptr noundef nonnull %6) #5
  %9 = call i32 @sm3_xmss_key_get_height(ptr noundef %1, ptr noundef nonnull %7)
  %10 = getelementptr inbounds i8, ptr %1, i64 68
  %11 = getelementptr inbounds i8, ptr %1, i64 132
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %1, i64 4
  %14 = load i32, ptr %7, align 4, !tbaa !11
  %15 = getelementptr inbounds i8, ptr %1, i64 136
  %16 = load ptr, ptr %15, align 8, !tbaa !12
  %17 = getelementptr inbounds i8, ptr %2, i64 36
  %18 = getelementptr inbounds i8, ptr %2, i64 2180
  call void @sm3_xmss_do_sign(ptr noundef nonnull %10, i32 noundef %12, ptr noundef nonnull %13, ptr noundef nonnull %5, i32 noundef %14, ptr noundef %16, ptr noundef nonnull %6, ptr noundef nonnull %17, ptr noundef nonnull %18)
  %19 = load i32, ptr %11, align 4, !tbaa !5
  %20 = lshr i32 %19, 24
  %21 = trunc nuw i32 %20 to i8
  store i8 %21, ptr %2, align 1, !tbaa !13
  %22 = load i32, ptr %11, align 4, !tbaa !5
  %23 = lshr i32 %22, 16
  %24 = trunc i32 %23 to i8
  %25 = getelementptr inbounds i8, ptr %2, i64 1
  store i8 %24, ptr %25, align 1, !tbaa !13
  %26 = load i32, ptr %11, align 4, !tbaa !5
  %27 = lshr i32 %26, 8
  %28 = trunc i32 %27 to i8
  %29 = getelementptr inbounds i8, ptr %2, i64 2
  store i8 %28, ptr %29, align 1, !tbaa !13
  %30 = load i32, ptr %11, align 4, !tbaa !5
  %31 = trunc i32 %30 to i8
  %32 = getelementptr inbounds i8, ptr %2, i64 3
  store i8 %31, ptr %32, align 1, !tbaa !13
  %33 = getelementptr inbounds i8, ptr %2, i64 4
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(32) %33, ptr noundef nonnull align 8 dereferenceable(32) %0, i64 32, i1 false)
  %34 = load i32, ptr %7, align 4, !tbaa !11
  %35 = shl i32 %34, 5
  %36 = add i32 %35, 2180
  %37 = zext i32 %36 to i64
  store i64 %37, ptr %3, align 8, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %7) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %6) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %5) #5
  ret i32 1
}

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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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 #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 132}
!6 = !{!"", !7, i64 0, !8, i64 4, !8, i64 36, !8, i64 68, !8, i64 100, !7, i64 132, !10, i64 136}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!6, !10, i64 136}
!13 = !{!8, !8, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"long", !8, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass