; 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_and_envelop = external hidden unnamed_addr constant [21 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_and_enveloped_data_encipher_to_der(ptr noundef, i64 noundef, ptr noundef, i64 noundef, i32 noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, i32 noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @cms_sign_and_envelop(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4, i64 noundef %5, i32 noundef %6, ptr noundef %7, i64 noundef %8, ptr noundef %9, i64 noundef %10, i32 noundef %11, ptr noundef %12, i64 noundef %13, ptr noundef %14, i64 noundef %15, ptr noundef %16, i64 noundef %17, ptr noundef %18, i64 noundef %19) #2 {
  %21 = alloca i32, align 4
  %22 = alloca ptr, align 8
  %23 = alloca ptr, align 8
  %24 = alloca ptr, align 8
  %25 = alloca i64, align 8
  %26 = alloca ptr, align 8
  %27 = alloca i64, align 8
  %28 = alloca i32, align 4
  %29 = alloca ptr, align 8
  %30 = alloca i64, align 8
  %31 = alloca ptr, align 8
  %32 = alloca i64, align 8
  %33 = alloca i32, align 4
  %34 = alloca ptr, align 8
  %35 = alloca i64, align 8
  %36 = alloca ptr, align 8
  %37 = alloca i64, align 8
  %38 = alloca ptr, align 8
  %39 = alloca i64, align 8
  %40 = alloca ptr, align 8
  %41 = alloca i64, align 8
  %42 = alloca i32, align 4
  %43 = alloca i64, align 8
  %44 = alloca i32, align 4
  %45 = alloca [1 x i8], align 1
  store ptr %0, ptr %22, align 8, !tbaa !5
  store ptr %1, ptr %23, align 8, !tbaa !5
  store ptr %2, ptr %24, align 8, !tbaa !5
  store i64 %3, ptr %25, align 8, !tbaa !9
  store ptr %4, ptr %26, align 8, !tbaa !5
  store i64 %5, ptr %27, align 8, !tbaa !9
  store i32 %6, ptr %28, align 4, !tbaa !11
  store ptr %7, ptr %29, align 8, !tbaa !5
  store i64 %8, ptr %30, align 8, !tbaa !9
  store ptr %9, ptr %31, align 8, !tbaa !5
  store i64 %10, ptr %32, align 8, !tbaa !9
  store i32 %11, ptr %33, align 4, !tbaa !11
  store ptr %12, ptr %34, align 8, !tbaa !5
  store i64 %13, ptr %35, align 8, !tbaa !9
  store ptr %14, ptr %36, align 8, !tbaa !5
  store i64 %15, ptr %37, align 8, !tbaa !9
  store ptr %16, ptr %38, align 8, !tbaa !5
  store i64 %17, ptr %39, align 8, !tbaa !9
  store ptr %18, ptr %40, align 8, !tbaa !5
  store i64 %19, ptr %41, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %42) #3
  store i32 121, ptr %42, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %43) #3
  store i64 0, ptr %43, align 8, !tbaa !9
  %46 = load ptr, ptr %24, align 8, !tbaa !5
  %47 = load i64, ptr %25, align 8, !tbaa !9
  %48 = load ptr, ptr %26, align 8, !tbaa !5
  %49 = load i64, ptr %27, align 8, !tbaa !9
  %50 = load i32, ptr %28, align 4, !tbaa !11
  %51 = load ptr, ptr %29, align 8, !tbaa !5
  %52 = load i64, ptr %30, align 8, !tbaa !9
  %53 = load ptr, ptr %31, align 8, !tbaa !5
  %54 = load i64, ptr %32, align 8, !tbaa !9
  %55 = load i32, ptr %33, align 4, !tbaa !11
  %56 = load ptr, ptr %34, align 8, !tbaa !5
  %57 = load i64, ptr %35, align 8, !tbaa !9
  %58 = load ptr, ptr %36, align 8, !tbaa !5
  %59 = load i64, ptr %37, align 8, !tbaa !9
  %60 = load ptr, ptr %38, align 8, !tbaa !5
  %61 = load i64, ptr %39, align 8, !tbaa !9
  %62 = load ptr, ptr %40, align 8, !tbaa !5
  %63 = load i64, ptr %41, align 8, !tbaa !9
  %64 = call i32 @cms_signed_and_enveloped_data_encipher_to_der(ptr noundef %46, i64 noundef %47, ptr noundef %48, i64 noundef %49, i32 noundef %50, ptr noundef %51, i64 noundef %52, ptr noundef %53, i64 noundef %54, i32 noundef %55, ptr noundef %56, i64 noundef %57, ptr noundef %58, i64 noundef %59, ptr noundef %60, i64 noundef %61, ptr noundef %62, i64 noundef %63, ptr noundef null, ptr noundef %43)
  %65 = icmp ne i32 %64, 1
  br i1 %65, label %66, label %72

66:                                               ; preds = %20
  br label %67

67:                                               ; preds = %66
  %68 = load ptr, ptr @stderr, align 8, !tbaa !5
  %69 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %68, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 2325, ptr noundef @__FUNCTION__.cms_sign_and_envelop) #3
  br label %70

70:                                               ; preds = %67
  br label %71

71:                                               ; preds = %70
  store i32 -1, ptr %21, align 4
  store i32 1, ptr %44, align 4
  br label %126

72:                                               ; preds = %20
  %73 = load ptr, ptr %23, align 8, !tbaa !5
  store i64 0, ptr %73, align 8, !tbaa !9
  %74 = load ptr, ptr %22, align 8, !tbaa !5
  %75 = icmp ne ptr %74, null
  br i1 %75, label %91, label %76

76:                                               ; preds = %72
  call void @llvm.lifetime.start.p0(i64 1, ptr %45) #3
  %77 = load i32, ptr %42, align 4, !tbaa !11
  %78 = getelementptr inbounds [1 x i8], ptr %45, i64 0, i64 0
  %79 = load i64, ptr %43, align 8, !tbaa !9
  %80 = load ptr, ptr %23, align 8, !tbaa !5
  %81 = call i32 @cms_content_info_to_der(i32 noundef %77, ptr noundef %78, i64 noundef %79, ptr noundef null, ptr noundef %80)
  %82 = icmp ne i32 %81, 1
  br i1 %82, label %83, label %89

83:                                               ; preds = %76
  br label %84

84:                                               ; preds = %83
  %85 = load ptr, ptr @stderr, align 8, !tbaa !5
  %86 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %85, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 2332, ptr noundef @__FUNCTION__.cms_sign_and_envelop) #3
  br label %87

87:                                               ; preds = %84
  br label %88

88:                                               ; preds = %87
  store i32 -1, ptr %21, align 4
  store i32 1, ptr %44, align 4
  br label %90

89:                                               ; preds = %76
  store i32 1, ptr %21, align 4
  store i32 1, ptr %44, align 4
  br label %90

90:                                               ; preds = %89, %88
  call void @llvm.lifetime.end.p0(i64 1, ptr %45) #3
  br label %126

91:                                               ; preds = %72
  %92 = load i32, ptr %42, align 4, !tbaa !11
  %93 = load i64, ptr %43, align 8, !tbaa !9
  %94 = load ptr, ptr %23, align 8, !tbaa !5
  %95 = call i32 @cms_content_info_header_to_der(i32 noundef %92, i64 noundef %93, ptr noundef %22, ptr noundef %94)
  %96 = icmp ne i32 %95, 1
  br i1 %96, label %119, label %97

97:                                               ; preds = %91
  %98 = load ptr, ptr %24, align 8, !tbaa !5
  %99 = load i64, ptr %25, align 8, !tbaa !9
  %100 = load ptr, ptr %26, align 8, !tbaa !5
  %101 = load i64, ptr %27, align 8, !tbaa !9
  %102 = load i32, ptr %28, align 4, !tbaa !11
  %103 = load ptr, ptr %29, align 8, !tbaa !5
  %104 = load i64, ptr %30, align 8, !tbaa !9
  %105 = load ptr, ptr %31, align 8, !tbaa !5
  %106 = load i64, ptr %32, align 8, !tbaa !9
  %107 = load i32, ptr %33, align 4, !tbaa !11
  %108 = load ptr, ptr %34, align 8, !tbaa !5
  %109 = load i64, ptr %35, align 8, !tbaa !9
  %110 = load ptr, ptr %36, align 8, !tbaa !5
  %111 = load i64, ptr %37, align 8, !tbaa !9
  %112 = load ptr, ptr %38, align 8, !tbaa !5
  %113 = load i64, ptr %39, align 8, !tbaa !9
  %114 = load ptr, ptr %40, align 8, !tbaa !5
  %115 = load i64, ptr %41, align 8, !tbaa !9
  %116 = load ptr, ptr %23, align 8, !tbaa !5
  %117 = call i32 @cms_signed_and_enveloped_data_encipher_to_der(ptr noundef %98, i64 noundef %99, ptr noundef %100, i64 noundef %101, i32 noundef %102, ptr noundef %103, i64 noundef %104, ptr noundef %105, i64 noundef %106, i32 noundef %107, ptr noundef %108, i64 noundef %109, ptr noundef %110, i64 noundef %111, ptr noundef %112, i64 noundef %113, ptr noundef %114, i64 noundef %115, ptr noundef %22, ptr noundef %116)
  %118 = icmp ne i32 %117, 1
  br i1 %118, label %119, label %125

119:                                              ; preds = %97, %91
  br label %120

120:                                              ; preds = %119
  %121 = load ptr, ptr @stderr, align 8, !tbaa !5
  %122 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %121, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 2347, ptr noundef @__FUNCTION__.cms_sign_and_envelop) #3
  br label %123

123:                                              ; preds = %120
  br label %124

124:                                              ; preds = %123
  store i32 -1, ptr %21, align 4
  store i32 1, ptr %44, align 4
  br label %126

125:                                              ; preds = %97
  store i32 1, ptr %21, align 4
  store i32 1, ptr %44, align 4
  br label %126

126:                                              ; preds = %125, %124, %90, %71
  call void @llvm.lifetime.end.p0(i64 8, ptr %43) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %42) #3
  %127 = load i32, ptr %21, align 4
  ret i32 %127
}

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_and_envelop = external hidden unnamed_addr constant [21 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_and_enveloped_data_encipher_to_der(ptr noundef, i64 noundef, ptr noundef, i64 noundef, i32 noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, i32 noundef, ptr noundef, i64 noundef, ptr noundef, i64 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_and_envelop(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4, i64 noundef %5, i32 noundef %6, ptr noundef %7, i64 noundef %8, ptr noundef %9, i64 noundef %10, i32 noundef %11, ptr noundef %12, i64 noundef %13, ptr noundef %14, i64 noundef %15, ptr noundef %16, i64 noundef %17, ptr noundef %18, i64 noundef %19) local_unnamed_addr #2 {
  %21 = alloca ptr, align 8
  %22 = alloca i64, align 8
  %23 = alloca [1 x i8], align 1
  store ptr %0, ptr %21, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %22) #3
  store i64 0, ptr %22, align 8, !tbaa !9
  %24 = call i32 @cms_signed_and_enveloped_data_encipher_to_der(ptr noundef %2, i64 noundef %3, ptr noundef %4, i64 noundef %5, i32 noundef %6, ptr noundef %7, i64 noundef %8, ptr noundef %9, i64 noundef %10, i32 noundef %11, ptr noundef %12, i64 noundef %13, ptr noundef %14, i64 noundef %15, ptr noundef %16, i64 noundef %17, ptr noundef %18, i64 noundef %19, ptr noundef null, ptr noundef nonnull %22)
  %.not = icmp eq i32 %24, 1
  br i1 %.not, label %28, label %25

25:                                               ; preds = %20
  %26 = load ptr, ptr @stderr, align 8, !tbaa !5
  %27 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %26, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 2325, ptr noundef nonnull @__FUNCTION__.cms_sign_and_envelop) #4
  br label %44

28:                                               ; preds = %20
  store i64 0, ptr %1, align 8, !tbaa !9
  %.not42 = icmp eq ptr %0, null
  br i1 %.not42, label %29, label %36

29:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %23) #3
  %30 = load i64, ptr %22, align 8, !tbaa !9
  %31 = call i32 @cms_content_info_to_der(i32 noundef 121, ptr noundef nonnull %23, i64 noundef %30, ptr noundef null, ptr noundef nonnull %1)
  %.not43 = icmp eq i32 %31, 1
  br i1 %.not43, label %35, label %32

32:                                               ; preds = %29
  %33 = load ptr, ptr @stderr, align 8, !tbaa !5
  %34 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %33, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 2332, ptr noundef nonnull @__FUNCTION__.cms_sign_and_envelop) #4
  br label %35

35:                                               ; preds = %29, %32
  %.0 = phi i32 [ -1, %32 ], [ 1, %29 ]
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %23) #3
  br label %44

36:                                               ; preds = %28
  %37 = load i64, ptr %22, align 8, !tbaa !9
  %38 = call i32 @cms_content_info_header_to_der(i32 noundef 121, i64 noundef %37, ptr noundef nonnull %21, ptr noundef nonnull %1)
  %.not44 = icmp eq i32 %38, 1
  br i1 %.not44, label %39, label %41

39:                                               ; preds = %36
  %40 = call i32 @cms_signed_and_enveloped_data_encipher_to_der(ptr noundef %2, i64 noundef %3, ptr noundef %4, i64 noundef %5, i32 noundef %6, ptr noundef %7, i64 noundef %8, ptr noundef %9, i64 noundef %10, i32 noundef %11, ptr noundef %12, i64 noundef %13, ptr noundef %14, i64 noundef %15, ptr noundef %16, i64 noundef %17, ptr noundef %18, i64 noundef %19, ptr noundef nonnull %21, ptr noundef nonnull %1)
  %.not45 = icmp eq i32 %40, 1
  br i1 %.not45, label %44, label %41

41:                                               ; preds = %36, %39
  %42 = load ptr, ptr @stderr, align 8, !tbaa !5
  %43 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %42, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 2347, ptr noundef nonnull @__FUNCTION__.cms_sign_and_envelop) #4
  br label %44

44:                                               ; preds = %39, %41, %35, %25
  %.1 = phi i32 [ -1, %25 ], [ -1, %41 ], [ %.0, %35 ], [ 1, %39 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %22) #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