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

@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_sign = external hidden unnamed_addr constant [9 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_content_info_header_to_der(i32 noundef, i64 noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @cms_content_info_to_der(i32 noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @cms_signed_data_sign_to_der(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_sign(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3, i32 noundef %4, ptr noundef %5, i64 noundef %6, ptr noundef %7, i64 noundef %8) #2 {
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  %15 = alloca i32, align 4
  %16 = alloca ptr, align 8
  %17 = alloca i64, align 8
  %18 = alloca ptr, align 8
  %19 = alloca i64, align 8
  %20 = alloca i32, align 4
  %21 = alloca i64, align 8
  %22 = alloca i32, align 4
  %23 = alloca [1 x i8], align 1
  store ptr %0, ptr %11, align 8, !tbaa !5
  store ptr %1, ptr %12, align 8, !tbaa !5
  store ptr %2, ptr %13, align 8, !tbaa !5
  store i64 %3, ptr %14, align 8, !tbaa !9
  store i32 %4, ptr %15, align 4, !tbaa !11
  store ptr %5, ptr %16, align 8, !tbaa !5
  store i64 %6, ptr %17, align 8, !tbaa !9
  store ptr %7, ptr %18, align 8, !tbaa !5
  store i64 %8, ptr %19, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #3
  store i32 119, ptr %20, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #3
  store i64 0, ptr %21, align 8, !tbaa !9
  %24 = load ptr, ptr %13, align 8, !tbaa !5
  %25 = load i64, ptr %14, align 8, !tbaa !9
  %26 = load i32, ptr %15, align 4, !tbaa !11
  %27 = load ptr, ptr %16, align 8, !tbaa !5
  %28 = load i64, ptr %17, align 8, !tbaa !9
  %29 = load ptr, ptr %18, align 8, !tbaa !5
  %30 = load i64, ptr %19, align 8, !tbaa !9
  %31 = call i32 @cms_signed_data_sign_to_der(ptr noundef %24, i64 noundef %25, i32 noundef %26, ptr noundef %27, i64 noundef %28, ptr noundef %29, i64 noundef %30, ptr noundef null, ptr noundef %21)
  %32 = icmp ne i32 %31, 1
  br i1 %32, label %33, label %39

33:                                               ; preds = %9
  br label %34

34:                                               ; preds = %33
  %35 = load ptr, ptr @stderr, align 8, !tbaa !5
  %36 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %35, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 2145, ptr noundef @__FUNCTION__.cms_sign) #3
  br label %37

37:                                               ; preds = %34
  br label %38

38:                                               ; preds = %37
  store i32 -1, ptr %10, align 4
  store i32 1, ptr %22, align 4
  br label %82

39:                                               ; preds = %9
  %40 = load ptr, ptr %12, align 8, !tbaa !5
  store i64 0, ptr %40, align 8, !tbaa !9
  %41 = load ptr, ptr %11, align 8, !tbaa !5
  %42 = icmp ne ptr %41, null
  br i1 %42, label %58, label %43

43:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 1, ptr %23) #3
  %44 = load i32, ptr %20, align 4, !tbaa !11
  %45 = getelementptr inbounds [1 x i8], ptr %23, i64 0, i64 0
  %46 = load i64, ptr %21, align 8, !tbaa !9
  %47 = load ptr, ptr %12, align 8, !tbaa !5
  %48 = call i32 @cms_content_info_to_der(i32 noundef %44, ptr noundef %45, i64 noundef %46, ptr noundef null, ptr noundef %47)
  %49 = icmp ne i32 %48, 1
  br i1 %49, label %50, label %56

50:                                               ; preds = %43
  br label %51

51:                                               ; preds = %50
  %52 = load ptr, ptr @stderr, align 8, !tbaa !5
  %53 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %52, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 2152, ptr noundef @__FUNCTION__.cms_sign) #3
  br label %54

54:                                               ; preds = %51
  br label %55

55:                                               ; preds = %54
  store i32 -1, ptr %10, align 4
  store i32 1, ptr %22, align 4
  br label %57

56:                                               ; preds = %43
  store i32 1, ptr %10, align 4
  store i32 1, ptr %22, align 4
  br label %57

57:                                               ; preds = %56, %55
  call void @llvm.lifetime.end.p0(i64 1, ptr %23) #3
  br label %82

58:                                               ; preds = %39
  %59 = load i32, ptr %20, align 4, !tbaa !11
  %60 = load i64, ptr %21, align 8, !tbaa !9
  %61 = load ptr, ptr %12, align 8, !tbaa !5
  %62 = call i32 @cms_content_info_header_to_der(i32 noundef %59, i64 noundef %60, ptr noundef %11, ptr noundef %61)
  %63 = icmp ne i32 %62, 1
  br i1 %63, label %75, label %64

64:                                               ; preds = %58
  %65 = load ptr, ptr %13, align 8, !tbaa !5
  %66 = load i64, ptr %14, align 8, !tbaa !9
  %67 = load i32, ptr %15, align 4, !tbaa !11
  %68 = load ptr, ptr %16, align 8, !tbaa !5
  %69 = load i64, ptr %17, align 8, !tbaa !9
  %70 = load ptr, ptr %18, align 8, !tbaa !5
  %71 = load i64, ptr %19, align 8, !tbaa !9
  %72 = load ptr, ptr %12, align 8, !tbaa !5
  %73 = call i32 @cms_signed_data_sign_to_der(ptr noundef %65, i64 noundef %66, i32 noundef %67, ptr noundef %68, i64 noundef %69, ptr noundef %70, i64 noundef %71, ptr noundef %11, ptr noundef %72)
  %74 = icmp ne i32 %73, 1
  br i1 %74, label %75, label %81

75:                                               ; preds = %64, %58
  br label %76

76:                                               ; preds = %75
  %77 = load ptr, ptr @stderr, align 8, !tbaa !5
  %78 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %77, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 2163, ptr noundef @__FUNCTION__.cms_sign) #3
  br label %79

79:                                               ; preds = %76
  br label %80

80:                                               ; preds = %79
  store i32 -1, ptr %10, align 4
  store i32 1, ptr %22, align 4
  br label %82

81:                                               ; preds = %64
  store i32 1, ptr %10, align 4
  store i32 1, ptr %22, align 4
  br label %82

82:                                               ; preds = %81, %80, %57, %38
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #3
  %83 = load i32, ptr %10, align 4
  ret i32 %83
}

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 = { 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 = !{!12, !12, i64 0}
!12 = !{!"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"

@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_sign = external hidden unnamed_addr constant [9 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_content_info_header_to_der(i32 noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @cms_content_info_to_der(i32 noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @cms_signed_data_sign_to_der(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_sign(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3, i32 noundef %4, ptr noundef %5, i64 noundef %6, ptr noundef %7, i64 noundef %8) local_unnamed_addr #2 {
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca [1 x i8], align 1
  store ptr %0, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %11) #3
  store i64 0, ptr %11, align 8, !tbaa !9
  %13 = call i32 @cms_signed_data_sign_to_der(ptr noundef %2, i64 noundef %3, i32 noundef %4, ptr noundef %5, i64 noundef %6, ptr noundef %7, i64 noundef %8, ptr noundef null, ptr noundef nonnull %11)
  %.not = icmp eq i32 %13, 1
  br i1 %.not, label %17, label %14

14:                                               ; preds = %9
  %15 = load ptr, ptr @stderr, align 8, !tbaa !5
  %16 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %15, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 2145, ptr noundef nonnull @__FUNCTION__.cms_sign) #4
  br label %33

17:                                               ; preds = %9
  store i64 0, ptr %1, align 8, !tbaa !9
  %.not20 = icmp eq ptr %0, null
  br i1 %.not20, label %18, label %25

18:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %12) #3
  %19 = load i64, ptr %11, align 8, !tbaa !9
  %20 = call i32 @cms_content_info_to_der(i32 noundef 119, ptr noundef nonnull %12, i64 noundef %19, ptr noundef null, ptr noundef nonnull %1)
  %.not21 = icmp eq i32 %20, 1
  br i1 %.not21, label %24, label %21

21:                                               ; preds = %18
  %22 = load ptr, ptr @stderr, align 8, !tbaa !5
  %23 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %22, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 2152, ptr noundef nonnull @__FUNCTION__.cms_sign) #4
  br label %24

24:                                               ; preds = %18, %21
  %.0 = phi i32 [ -1, %21 ], [ 1, %18 ]
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %12) #3
  br label %33

25:                                               ; preds = %17
  %26 = load i64, ptr %11, align 8, !tbaa !9
  %27 = call i32 @cms_content_info_header_to_der(i32 noundef 119, i64 noundef %26, ptr noundef nonnull %10, ptr noundef nonnull %1)
  %.not22 = icmp eq i32 %27, 1
  br i1 %.not22, label %28, label %30

28:                                               ; preds = %25
  %29 = call i32 @cms_signed_data_sign_to_der(ptr noundef %2, i64 noundef %3, i32 noundef %4, ptr noundef %5, i64 noundef %6, ptr noundef %7, i64 noundef %8, ptr noundef nonnull %10, ptr noundef nonnull %1)
  %.not23 = icmp eq i32 %29, 1
  br i1 %.not23, label %33, label %30

30:                                               ; preds = %25, %28
  %31 = load ptr, ptr @stderr, align 8, !tbaa !5
  %32 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %31, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 2163, ptr noundef nonnull @__FUNCTION__.cms_sign) #4
  br label %33

33:                                               ; preds = %28, %30, %24, %14
  %.1 = phi i32 [ -1, %14 ], [ -1, %30 ], [ %.0, %24 ], [ 1, %28 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %11) #3
  ret i32 %.1
}

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 = { nounwind }
attributes #4 = { 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 = !{!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}


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