; 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 }
%struct.SM3_XMSS_KEY = type { i32, [32 x i8], [32 x i8], [32 x i8], [32 x i8], i32, ptr }
%struct.SM3_XMSS_SIGN_CTX = type { [32 x i8], %struct.SM3_CTX }

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

declare void @sm3_update(ptr noundef, ptr noundef, i64 noundef) #1

declare void @sm3_finish(ptr noundef, ptr noundef) #1

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @sm3_xmss_sign_init(ptr noundef %0, ptr noundef %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca %struct.SM3_CTX, align 8
  %6 = alloca [32 x i8], align 16
  %7 = alloca [32 x i8], align 16
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 112, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr %6) #4
  call void @llvm.memset.p0.i64(ptr align 16 %6, i8 0, i64 32, i1 false)
  call void @llvm.lifetime.start.p0(i64 32, ptr %7) #4
  call void @llvm.memset.p0.i64(ptr align 16 %7, i8 0, i64 32, i1 false)
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.SM3_XMSS_KEY, ptr %8, i32 0, i32 4
  %10 = getelementptr inbounds [32 x i8], ptr %9, i64 0, i64 0
  call void @hash256_prf_init(ptr noundef %5, ptr noundef %10)
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.SM3_XMSS_KEY, ptr %11, i32 0, i32 5
  %13 = load i32, ptr %12, align 4, !tbaa !9
  %14 = lshr i32 %13, 24
  %15 = trunc i32 %14 to i8
  %16 = getelementptr inbounds [32 x i8], ptr %7, i64 0, i64 0
  %17 = getelementptr inbounds i8, ptr %16, i64 28
  %18 = getelementptr inbounds i8, ptr %17, i64 0
  store i8 %15, ptr %18, align 1, !tbaa !12
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.SM3_XMSS_KEY, ptr %19, i32 0, i32 5
  %21 = load i32, ptr %20, align 4, !tbaa !9
  %22 = lshr i32 %21, 16
  %23 = trunc i32 %22 to i8
  %24 = getelementptr inbounds [32 x i8], ptr %7, i64 0, i64 0
  %25 = getelementptr inbounds i8, ptr %24, i64 28
  %26 = getelementptr inbounds i8, ptr %25, i64 1
  store i8 %23, ptr %26, align 1, !tbaa !12
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.SM3_XMSS_KEY, ptr %27, i32 0, i32 5
  %29 = load i32, ptr %28, align 4, !tbaa !9
  %30 = lshr i32 %29, 8
  %31 = trunc i32 %30 to i8
  %32 = getelementptr inbounds [32 x i8], ptr %7, i64 0, i64 0
  %33 = getelementptr inbounds i8, ptr %32, i64 28
  %34 = getelementptr inbounds i8, ptr %33, i64 2
  store i8 %31, ptr %34, align 1, !tbaa !12
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.SM3_XMSS_KEY, ptr %35, i32 0, i32 5
  %37 = load i32, ptr %36, align 4, !tbaa !9
  %38 = trunc i32 %37 to i8
  %39 = getelementptr inbounds [32 x i8], ptr %7, i64 0, i64 0
  %40 = getelementptr inbounds i8, ptr %39, i64 28
  %41 = getelementptr inbounds i8, ptr %40, i64 3
  store i8 %38, ptr %41, align 1, !tbaa !12
  %42 = getelementptr inbounds [32 x i8], ptr %7, i64 0, i64 0
  call void @sm3_update(ptr noundef %5, ptr noundef %42, i64 noundef 32)
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.SM3_XMSS_SIGN_CTX, ptr %43, i32 0, i32 0
  %45 = getelementptr inbounds [32 x i8], ptr %44, i64 0, i64 0
  call void @sm3_finish(ptr noundef %5, ptr noundef %45)
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.SM3_XMSS_SIGN_CTX, ptr %46, i32 0, i32 1
  call void @sm3_init(ptr noundef %47)
  %48 = getelementptr inbounds [32 x i8], ptr %6, i64 0, i64 31
  store i8 2, ptr %48, align 1, !tbaa !12
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.SM3_XMSS_SIGN_CTX, ptr %49, i32 0, i32 1
  %51 = getelementptr inbounds [32 x i8], ptr %6, i64 0, i64 0
  call void @sm3_update(ptr noundef %50, ptr noundef %51, i64 noundef 32)
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.SM3_XMSS_SIGN_CTX, ptr %52, i32 0, i32 1
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.SM3_XMSS_SIGN_CTX, ptr %54, i32 0, i32 0
  %56 = getelementptr inbounds [32 x i8], ptr %55, i64 0, i64 0
  call void @sm3_update(ptr noundef %53, ptr noundef %56, i64 noundef 32)
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.SM3_XMSS_SIGN_CTX, ptr %57, i32 0, i32 1
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.SM3_XMSS_KEY, ptr %59, i32 0, i32 2
  %61 = getelementptr inbounds [32 x i8], ptr %60, i64 0, i64 0
  call void @sm3_update(ptr noundef %58, ptr noundef %61, i64 noundef 32)
  %62 = load ptr, ptr %3, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.SM3_XMSS_SIGN_CTX, ptr %62, i32 0, i32 1
  %64 = getelementptr inbounds [32 x i8], ptr %7, i64 0, i64 0
  call void @sm3_update(ptr noundef %63, ptr noundef %64, i64 noundef 32)
  call void @llvm.lifetime.end.p0(i64 32, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 112, ptr %5) #4
  ret i32 1
}

declare void @sm3_init(ptr noundef) #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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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, !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 = !{!7, !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"

%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

declare void @sm3_update(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

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

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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @sm3_xmss_sign_init(ptr noundef %0, ptr noundef %1) local_unnamed_addr #3 {
  %3 = alloca %struct.SM3_CTX, align 8
  %4 = alloca [32 x i8], align 16
  %5 = alloca [32 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 112, ptr nonnull %3) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %4) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(32) %4, i8 0, i64 32, i1 false)
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %5) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(32) %5, i8 0, i64 32, i1 false)
  %6 = getelementptr inbounds i8, ptr %1, i64 100
  call void @hash256_prf_init(ptr noundef nonnull %3, ptr noundef nonnull %6)
  %7 = getelementptr inbounds i8, ptr %1, i64 132
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %9 = lshr i32 %8, 24
  %10 = trunc nuw i32 %9 to i8
  %11 = getelementptr inbounds i8, ptr %5, i64 28
  store i8 %10, ptr %11, align 4, !tbaa !11
  %12 = lshr i32 %8, 16
  %13 = trunc i32 %12 to i8
  %14 = getelementptr inbounds i8, ptr %5, i64 29
  store i8 %13, ptr %14, align 1, !tbaa !11
  %15 = lshr i32 %8, 8
  %16 = trunc i32 %15 to i8
  %17 = getelementptr inbounds i8, ptr %5, i64 30
  store i8 %16, ptr %17, align 2, !tbaa !11
  %18 = trunc i32 %8 to i8
  %19 = getelementptr inbounds i8, ptr %5, i64 31
  store i8 %18, ptr %19, align 1, !tbaa !11
  call void @sm3_update(ptr noundef nonnull %3, ptr noundef nonnull %5, i64 noundef 32) #4
  call void @sm3_finish(ptr noundef nonnull %3, ptr noundef %0) #4
  %20 = getelementptr inbounds i8, ptr %0, i64 32
  call void @sm3_init(ptr noundef nonnull %20) #4
  %21 = getelementptr inbounds i8, ptr %4, i64 31
  store i8 2, ptr %21, align 1, !tbaa !11
  call void @sm3_update(ptr noundef nonnull %20, ptr noundef nonnull %4, i64 noundef 32) #4
  call void @sm3_update(ptr noundef nonnull %20, ptr noundef %0, i64 noundef 32) #4
  %22 = getelementptr inbounds i8, ptr %1, i64 36
  call void @sm3_update(ptr noundef nonnull %20, ptr noundef nonnull %22, i64 noundef 32) #4
  call void @sm3_update(ptr noundef nonnull %20, ptr noundef nonnull %5, i64 noundef 32) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 112, ptr nonnull %3) #4
  ret i32 1
}

declare void @sm3_init(ptr noundef) local_unnamed_addr #1

attributes #0 = { mustprogress 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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, !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 = !{!8, !8, i64 0}


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