; 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.SM3_LMS_KEY = type { %struct.SM3_LMS_PUBLIC_KEY, ptr, [32 x i8], i32 }
%struct.SM3_LMS_PUBLIC_KEY = type { [4 x i8], [4 x i8], [16 x i8], [32 x i8] }

@.str.16 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.26 = external hidden unnamed_addr constant [1 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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @sm3_lms_key_print(ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4) #1 {
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  store ptr %4, ptr %10, align 8, !tbaa !5
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = load i32, ptr %7, align 4, !tbaa !9
  %14 = load i32, ptr %8, align 4, !tbaa !9
  %15 = load ptr, ptr %9, align 8, !tbaa !5
  %16 = call i32 (ptr, i32, i32, ptr, ...) @format_print(ptr noundef %12, i32 noundef %13, i32 noundef %14, ptr noundef @.str.16, ptr noundef %15)
  %17 = load i32, ptr %8, align 4, !tbaa !9
  %18 = add nsw i32 %17, 4
  store i32 %18, ptr %8, align 4, !tbaa !9
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = load i32, ptr %7, align 4, !tbaa !9
  %21 = load i32, ptr %8, align 4, !tbaa !9
  %22 = load ptr, ptr %10, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.SM3_LMS_KEY, ptr %22, i32 0, i32 0
  %24 = call i32 @sm3_lms_public_key_print(ptr noundef %19, i32 noundef %20, i32 noundef %21, ptr noundef @.str.21, ptr noundef %23)
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = load i32, ptr %7, align 4, !tbaa !9
  %27 = load i32, ptr %8, align 4, !tbaa !9
  %28 = load ptr, ptr %10, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.SM3_LMS_KEY, ptr %28, i32 0, i32 2
  %30 = getelementptr inbounds [32 x i8], ptr %29, i64 0, i64 0
  %31 = call i32 @format_bytes(ptr noundef %25, i32 noundef %26, i32 noundef %27, ptr noundef @.str.22, ptr noundef %30, i64 noundef 32)
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = load i32, ptr %7, align 4, !tbaa !9
  %34 = load i32, ptr %8, align 4, !tbaa !9
  %35 = load ptr, ptr %10, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.SM3_LMS_KEY, ptr %35, i32 0, i32 3
  %37 = load i32, ptr %36, align 8, !tbaa !11
  %38 = call i32 (ptr, i32, i32, ptr, ...) @format_print(ptr noundef %32, i32 noundef %33, i32 noundef %34, ptr noundef @.str.23, i32 noundef %37)
  %39 = load ptr, ptr %10, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.SM3_LMS_KEY, ptr %39, i32 0, i32 1
  %41 = load ptr, ptr %40, align 8, !tbaa !14
  %42 = icmp ne ptr %41, null
  br i1 %42, label %43, label %75

43:                                               ; preds = %5
  %44 = load i32, ptr %7, align 4, !tbaa !9
  %45 = icmp ne i32 %44, 0
  br i1 %45, label %46, label %75

46:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = load i32, ptr %7, align 4, !tbaa !9
  %49 = load i32, ptr %8, align 4, !tbaa !9
  %50 = call i32 (ptr, i32, i32, ptr, ...) @format_print(ptr noundef %47, i32 noundef %48, i32 noundef %49, ptr noundef @.str.24)
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %51

51:                                               ; preds = %71, %46
  %52 = load i32, ptr %11, align 4, !tbaa !9
  %53 = icmp slt i32 %52, 63
  br i1 %53, label %54, label %74

54:                                               ; preds = %51
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  %56 = load i32, ptr %7, align 4, !tbaa !9
  %57 = load i32, ptr %8, align 4, !tbaa !9
  %58 = add nsw i32 %57, 4
  %59 = load i32, ptr %11, align 4, !tbaa !9
  %60 = call i32 (ptr, i32, i32, ptr, ...) @format_print(ptr noundef %55, i32 noundef %56, i32 noundef %58, ptr noundef @.str.25, i32 noundef %59)
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = load i32, ptr %7, align 4, !tbaa !9
  %63 = load ptr, ptr %10, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.SM3_LMS_KEY, ptr %63, i32 0, i32 1
  %65 = load ptr, ptr %64, align 8, !tbaa !14
  %66 = load i32, ptr %11, align 4, !tbaa !9
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [32 x i8], ptr %65, i64 %67
  %69 = getelementptr inbounds [32 x i8], ptr %68, i64 0, i64 0
  %70 = call i32 @format_bytes(ptr noundef %61, i32 noundef %62, i32 noundef 0, ptr noundef @.str.26, ptr noundef %69, i64 noundef 32)
  br label %71

71:                                               ; preds = %54
  %72 = load i32, ptr %11, align 4, !tbaa !9
  %73 = add nsw i32 %72, 1
  store i32 %73, ptr %11, align 4, !tbaa !9
  br label %51, !llvm.loop !15

74:                                               ; preds = %51
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %75

75:                                               ; preds = %74, %43, %5
  ret i32 1
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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, !10, i64 96}
!12 = !{!"", !13, i64 0, !6, i64 56, !7, i64 64, !10, i64 96}
!13 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 24}
!14 = !{!12, !6, i64 56}
!15 = distinct !{!15, !16}
!16 = !{!"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"

@.str.16 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.26 = external hidden unnamed_addr constant [1 x i8], align 1

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

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

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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @sm3_lms_key_print(ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4) local_unnamed_addr #0 {
  %6 = tail call i32 (ptr, i32, i32, ptr, ...) @format_print(ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef nonnull @.str.16, ptr noundef %3) #2
  %7 = add nsw i32 %2, 4
  %8 = tail call i32 @sm3_lms_public_key_print(ptr noundef %0, i32 noundef %1, i32 noundef %7, ptr noundef nonnull @.str.21, ptr noundef %4)
  %9 = getelementptr inbounds i8, ptr %4, i64 64
  %10 = tail call i32 @format_bytes(ptr noundef %0, i32 noundef %1, i32 noundef %7, ptr noundef nonnull @.str.22, ptr noundef nonnull %9, i64 noundef 32) #2
  %11 = getelementptr inbounds i8, ptr %4, i64 96
  %12 = load i32, ptr %11, align 8, !tbaa !5
  %13 = tail call i32 (ptr, i32, i32, ptr, ...) @format_print(ptr noundef %0, i32 noundef %1, i32 noundef %7, ptr noundef nonnull @.str.23, i32 noundef %12) #2
  %14 = getelementptr inbounds i8, ptr %4, i64 56
  %15 = load ptr, ptr %14, align 8, !tbaa !12
  %16 = icmp ne ptr %15, null
  %17 = icmp ne i32 %1, 0
  %or.cond = and i1 %17, %16
  br i1 %or.cond, label %18, label %.loopexit

18:                                               ; preds = %5
  %19 = tail call i32 (ptr, i32, i32, ptr, ...) @format_print(ptr noundef %0, i32 noundef %1, i32 noundef %7, ptr noundef nonnull @.str.24) #2
  %20 = add nsw i32 %2, 8
  br label %21

21:                                               ; preds = %18, %21
  %indvars.iv = phi i64 [ 0, %18 ], [ %indvars.iv.next, %21 ]
  %22 = trunc nuw nsw i64 %indvars.iv to i32
  %23 = tail call i32 (ptr, i32, i32, ptr, ...) @format_print(ptr noundef %0, i32 noundef %1, i32 noundef %20, ptr noundef nonnull @.str.25, i32 noundef %22) #2
  %24 = load ptr, ptr %14, align 8, !tbaa !12
  %25 = getelementptr inbounds [32 x i8], ptr %24, i64 %indvars.iv
  %26 = tail call i32 @format_bytes(ptr noundef %0, i32 noundef %1, i32 noundef 0, ptr noundef nonnull @.str.26, ptr noundef %25, i64 noundef 32) #2
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 63
  br i1 %exitcond.not, label %.loopexit, label %21, !llvm.loop !13

.loopexit:                                        ; preds = %21, %5
  ret i32 1
}

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 = { "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 }

!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, !11, i64 96}
!6 = !{!"", !7, i64 0, !10, i64 56, !8, i64 64, !11, i64 96}
!7 = !{!"", !8, i64 0, !8, i64 4, !8, i64 8, !8, i64 24}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!6, !10, i64 56}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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