; LLVM IR from guanzhi/GmSSL :: src (cms)

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

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [57 x i8], align 1
@__FUNCTION__.cms_signer_info_sign_to_der = external hidden unnamed_addr constant [28 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: nounwind
declare i32 @fprintf(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: nounwind uwtable
declare dso_local i32 @cms_signer_info_to_der(i32 noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, i32 noundef, ptr noundef, i64 noundef, i32 noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @cms_signer_info_sign_to_der(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4, i64 noundef %5, ptr noundef %6, i64 noundef %7, ptr noundef %8, i64 noundef %9, ptr noundef %10, ptr noundef %11) #2 {
  %13 = alloca i32, align 4
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca i64, align 8
  %18 = alloca ptr, align 8
  %19 = alloca i64, align 8
  %20 = alloca ptr, align 8
  %21 = alloca i64, align 8
  %22 = alloca ptr, align 8
  %23 = alloca i64, align 8
  %24 = alloca ptr, align 8
  %25 = alloca ptr, align 8
  %26 = alloca %struct.SM3_CTX, align 8
  %27 = alloca i32, align 4
  %28 = alloca [32 x i8], align 16
  %29 = alloca [72 x i8], align 16
  %30 = alloca i64, align 8
  %31 = alloca i32, align 4
  store ptr %0, ptr %14, align 8, !tbaa !5
  store ptr %1, ptr %15, align 8, !tbaa !5
  store ptr %2, ptr %16, align 8, !tbaa !5
  store i64 %3, ptr %17, align 8, !tbaa !9
  store ptr %4, ptr %18, align 8, !tbaa !5
  store i64 %5, ptr %19, align 8, !tbaa !9
  store ptr %6, ptr %20, align 8, !tbaa !5
  store i64 %7, ptr %21, align 8, !tbaa !9
  store ptr %8, ptr %22, align 8, !tbaa !5
  store i64 %9, ptr %23, align 8, !tbaa !9
  store ptr %10, ptr %24, align 8, !tbaa !5
  store ptr %11, ptr %25, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 112, ptr %26) #5
  %32 = load ptr, ptr %14, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %26, ptr align 8 %32, i64 112, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %27) #5
  store i32 1, ptr %27, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 32, ptr %28) #5
  call void @llvm.lifetime.start.p0(i64 72, ptr %29) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %30) #5
  store i64 71, ptr %30, align 8, !tbaa !9
  %33 = load ptr, ptr %20, align 8, !tbaa !5
  %34 = load i64, ptr %21, align 8, !tbaa !9
  call void @sm3_update(ptr noundef %26, ptr noundef %33, i64 noundef %34)
  %35 = getelementptr inbounds [32 x i8], ptr %28, i64 0, i64 0
  call void @sm3_finish(ptr noundef %26, ptr noundef %35)
  %36 = load ptr, ptr %15, align 8, !tbaa !5
  %37 = getelementptr inbounds [32 x i8], ptr %28, i64 0, i64 0
  %38 = load i64, ptr %30, align 8, !tbaa !9
  %39 = getelementptr inbounds [72 x i8], ptr %29, i64 0, i64 0
  %40 = call i32 @sm2_sign_fixlen(ptr noundef %36, ptr noundef %37, i64 noundef %38, ptr noundef %39)
  %41 = icmp ne i32 %40, 1
  br i1 %41, label %42, label %48

42:                                               ; preds = %12
  br label %43

43:                                               ; preds = %42
  %44 = load ptr, ptr @stderr, align 8, !tbaa !5
  %45 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %44, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 759, ptr noundef @__FUNCTION__.cms_signer_info_sign_to_der) #5
  br label %46

46:                                               ; preds = %43
  br label %47

47:                                               ; preds = %46
  store i32 -1, ptr %13, align 4
  store i32 1, ptr %31, align 4
  br label %70

48:                                               ; preds = %12
  %49 = load ptr, ptr %16, align 8, !tbaa !5
  %50 = load i64, ptr %17, align 8, !tbaa !9
  %51 = load ptr, ptr %18, align 8, !tbaa !5
  %52 = load i64, ptr %19, align 8, !tbaa !9
  %53 = load ptr, ptr %20, align 8, !tbaa !5
  %54 = load i64, ptr %21, align 8, !tbaa !9
  %55 = getelementptr inbounds [72 x i8], ptr %29, i64 0, i64 0
  %56 = load i64, ptr %30, align 8, !tbaa !9
  %57 = load ptr, ptr %22, align 8, !tbaa !5
  %58 = load i64, ptr %23, align 8, !tbaa !9
  %59 = load ptr, ptr %24, align 8, !tbaa !5
  %60 = load ptr, ptr %25, align 8, !tbaa !5
  %61 = call i32 @cms_signer_info_to_der(i32 noundef 1, ptr noundef %49, i64 noundef %50, ptr noundef %51, i64 noundef %52, i32 noundef 13, ptr noundef %53, i64 noundef %54, i32 noundef 16, ptr noundef %55, i64 noundef %56, ptr noundef %57, i64 noundef %58, ptr noundef %59, ptr noundef %60)
  %62 = icmp ne i32 %61, 1
  br i1 %62, label %63, label %69

63:                                               ; preds = %48
  br label %64

64:                                               ; preds = %63
  %65 = load ptr, ptr @stderr, align 8, !tbaa !5
  %66 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %65, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 767, ptr noundef @__FUNCTION__.cms_signer_info_sign_to_der) #5
  br label %67

67:                                               ; preds = %64
  br label %68

68:                                               ; preds = %67
  store i32 -1, ptr %13, align 4
  store i32 1, ptr %31, align 4
  br label %70

69:                                               ; preds = %48
  store i32 1, ptr %13, align 4
  store i32 1, ptr %31, align 4
  br label %70

70:                                               ; preds = %69, %68, %47
  call void @llvm.lifetime.end.p0(i64 8, ptr %30) #5
  call void @llvm.lifetime.end.p0(i64 72, ptr %29) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr %28) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %27) #5
  call void @llvm.lifetime.end.p0(i64 112, ptr %26) #5
  %71 = load i32, ptr %13, align 4
  ret i32 %71
}

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

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

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

declare i32 @sm2_sign_fixlen(ptr noundef, ptr noundef, i64 noundef, ptr noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind "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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { "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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{i64 0, i64 32, !12, i64 32, i64 8, !9, i64 40, i64 64, !12, i64 104, i64 8, !9}
!12 = !{!7, !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !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 }

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [57 x i8], align 1
@__FUNCTION__.cms_signer_info_sign_to_der = external hidden unnamed_addr constant [28 x i8], align 1

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

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) 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: nounwind uwtable
declare dso_local i32 @cms_signer_info_to_der(i32 noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, i32 noundef, ptr noundef, i64 noundef, i32 noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 2) i32 @cms_signer_info_sign_to_der(ptr nocapture noundef readonly %0, ptr noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4, i64 noundef %5, ptr noundef %6, i64 noundef %7, ptr noundef %8, i64 noundef %9, ptr noundef %10, ptr noundef %11) local_unnamed_addr #2 {
  %13 = alloca %struct.SM3_CTX, align 8
  %14 = alloca [32 x i8], align 16
  %15 = alloca [72 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 112, ptr nonnull %13) #5
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(112) %13, ptr noundef nonnull align 8 dereferenceable(112) %0, i64 112, i1 false), !tbaa.struct !5
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %14) #5
  call void @llvm.lifetime.start.p0(i64 72, ptr nonnull %15) #5
  call void @sm3_update(ptr noundef nonnull %13, ptr noundef %6, i64 noundef %7) #5
  call void @sm3_finish(ptr noundef nonnull %13, ptr noundef nonnull %14) #5
  %16 = call i32 @sm2_sign_fixlen(ptr noundef %1, ptr noundef nonnull %14, i64 noundef 71, ptr noundef nonnull %15) #5
  %.not = icmp eq i32 %16, 1
  br i1 %.not, label %17, label %.sink.split

17:                                               ; preds = %12
  %18 = call i32 @cms_signer_info_to_der(i32 noundef 1, ptr noundef %2, i64 noundef %3, ptr noundef %4, i64 noundef %5, i32 noundef 13, ptr noundef %6, i64 noundef %7, i32 noundef 16, ptr noundef nonnull %15, i64 noundef 71, ptr noundef %8, i64 noundef %9, ptr noundef %10, ptr noundef %11)
  %.not16 = icmp eq i32 %18, 1
  br i1 %.not16, label %21, label %.sink.split

.sink.split:                                      ; preds = %17, %12
  %.sink17 = phi i32 [ 759, %12 ], [ 767, %17 ]
  %19 = load ptr, ptr @stderr, align 8, !tbaa !11
  %20 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %19, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef %.sink17, ptr noundef nonnull @__FUNCTION__.cms_signer_info_sign_to_der) #6
  br label %21

21:                                               ; preds = %.sink.split, %17
  %.0 = phi i32 [ 1, %17 ], [ -1, %.sink.split ]
  call void @llvm.lifetime.end.p0(i64 72, ptr nonnull %15) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %14) #5
  call void @llvm.lifetime.end.p0(i64 112, ptr nonnull %13) #5
  ret i32 %.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) #3

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

declare void @sm3_finish(ptr noundef, ptr noundef) local_unnamed_addr #4

declare i32 @sm2_sign_fixlen(ptr noundef, ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #4

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nofree nounwind "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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { "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 }
attributes #6 = { cold 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 = !{i64 0, i64 32, !6, i64 32, i64 8, !9, i64 40, i64 64, !6, i64 104, i64 8, !9}
!6 = !{!7, !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}


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