; 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_enveloped_data_decrypt_from_der = external hidden unnamed_addr constant [36 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_enced_content_info_decrypt_from_der(ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #2

declare i32 @asn1_check(i32 noundef) #3

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @cms_enveloped_data_decrypt_from_der(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, i64 noundef %4, ptr noundef %5, ptr noundef %6, ptr noundef %7, ptr noundef %8, ptr noundef %9, ptr noundef %10, ptr noundef %11, ptr noundef %12, ptr noundef %13, ptr noundef %14, ptr noundef %15) #2 {
  %17 = alloca i32, align 4
  %18 = alloca ptr, align 8
  %19 = alloca ptr, align 8
  %20 = alloca i64, align 8
  %21 = alloca ptr, align 8
  %22 = alloca i64, align 8
  %23 = alloca ptr, align 8
  %24 = alloca ptr, align 8
  %25 = alloca ptr, align 8
  %26 = alloca ptr, align 8
  %27 = alloca ptr, align 8
  %28 = alloca ptr, align 8
  %29 = alloca ptr, align 8
  %30 = alloca ptr, align 8
  %31 = alloca ptr, align 8
  %32 = alloca ptr, align 8
  %33 = alloca ptr, align 8
  %34 = alloca i32, align 4
  %35 = alloca i32, align 4
  %36 = alloca ptr, align 8
  %37 = alloca i64, align 8
  %38 = alloca ptr, align 8
  %39 = alloca i64, align 8
  %40 = alloca i32, align 4
  %41 = alloca [32 x i8], align 16
  %42 = alloca i64, align 8
  %43 = alloca i32, align 4
  store ptr %0, ptr %18, align 8, !tbaa !5
  store ptr %1, ptr %19, align 8, !tbaa !5
  store i64 %2, ptr %20, align 8, !tbaa !9
  store ptr %3, ptr %21, align 8, !tbaa !5
  store i64 %4, ptr %22, align 8, !tbaa !9
  store ptr %5, ptr %23, align 8, !tbaa !5
  store ptr %6, ptr %24, align 8, !tbaa !5
  store ptr %7, ptr %25, align 8, !tbaa !5
  store ptr %8, ptr %26, align 8, !tbaa !5
  store ptr %9, ptr %27, align 8, !tbaa !5
  store ptr %10, ptr %28, align 8, !tbaa !5
  store ptr %11, ptr %29, align 8, !tbaa !5
  store ptr %12, ptr %30, align 8, !tbaa !5
  store ptr %13, ptr %31, align 8, !tbaa !5
  store ptr %14, ptr %32, align 8, !tbaa !5
  store ptr %15, ptr %33, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %34) #4
  store i32 0, ptr %34, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %35) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %36) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %37) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %38) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %39) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %40) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr %41) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %42) #4
  %44 = load ptr, ptr %32, align 8, !tbaa !5
  %45 = load ptr, ptr %33, align 8, !tbaa !5
  %46 = call i32 @cms_enveloped_data_from_der(ptr noundef %35, ptr noundef %36, ptr noundef %37, ptr noundef %38, ptr noundef %39, ptr noundef %44, ptr noundef %45)
  %47 = icmp ne i32 %46, 1
  br i1 %47, label %54, label %48

48:                                               ; preds = %16
  %49 = load i32, ptr %35, align 4, !tbaa !11
  %50 = icmp eq i32 %49, 1
  %51 = zext i1 %50 to i32
  %52 = call i32 @asn1_check(i32 noundef %51)
  %53 = icmp ne i32 %52, 1
  br i1 %53, label %54, label %55

54:                                               ; preds = %48, %16
  store i32 -1, ptr %17, align 4
  store i32 1, ptr %43, align 4
  br label %112

55:                                               ; preds = %48
  %56 = load ptr, ptr %36, align 8, !tbaa !5
  %57 = load ptr, ptr %26, align 8, !tbaa !5
  store ptr %56, ptr %57, align 8, !tbaa !5
  %58 = load i64, ptr %37, align 8, !tbaa !9
  %59 = load ptr, ptr %27, align 8, !tbaa !5
  store i64 %58, ptr %59, align 8, !tbaa !9
  br label %60

60:                                               ; preds = %83, %55
  %61 = load i64, ptr %37, align 8, !tbaa !9
  %62 = icmp ne i64 %61, 0
  br i1 %62, label %63, label %84

63:                                               ; preds = %60
  %64 = load ptr, ptr %18, align 8, !tbaa !5
  %65 = load ptr, ptr %19, align 8, !tbaa !5
  %66 = load i64, ptr %20, align 8, !tbaa !9
  %67 = load ptr, ptr %21, align 8, !tbaa !5
  %68 = load i64, ptr %22, align 8, !tbaa !9
  %69 = getelementptr inbounds [32 x i8], ptr %41, i64 0, i64 0
  %70 = call i32 @cms_recipient_info_decrypt_from_der(ptr noundef %64, ptr noundef %65, i64 noundef %66, ptr noundef %67, i64 noundef %68, ptr noundef %69, ptr noundef %42, i64 noundef 32, ptr noundef %36, ptr noundef %37)
  store i32 %70, ptr %34, align 4, !tbaa !11
  %71 = icmp slt i32 %70, 0
  br i1 %71, label %72, label %78

72:                                               ; preds = %63
  br label %73

73:                                               ; preds = %72
  %74 = load ptr, ptr @stderr, align 8, !tbaa !5
  %75 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %74, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 1609, ptr noundef @__FUNCTION__.cms_enveloped_data_decrypt_from_der) #4
  br label %76

76:                                               ; preds = %73
  br label %77

77:                                               ; preds = %76
  store i32 -1, ptr %17, align 4
  store i32 1, ptr %43, align 4
  br label %112

78:                                               ; preds = %63
  %79 = load i32, ptr %34, align 4, !tbaa !11
  %80 = icmp ne i32 %79, 0
  br i1 %80, label %81, label %82

81:                                               ; preds = %78
  br label %84

82:                                               ; preds = %78
  br label %83

83:                                               ; preds = %82
  br label %60, !llvm.loop !13

84:                                               ; preds = %81, %60
  %85 = load i32, ptr %34, align 4, !tbaa !11
  %86 = icmp ne i32 %85, 0
  br i1 %86, label %93, label %87

87:                                               ; preds = %84
  br label %88

88:                                               ; preds = %87
  %89 = load ptr, ptr @stderr, align 8, !tbaa !5
  %90 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %89, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 1616, ptr noundef @__FUNCTION__.cms_enveloped_data_decrypt_from_der) #4
  br label %91

91:                                               ; preds = %88
  br label %92

92:                                               ; preds = %91
  store i32 -1, ptr %17, align 4
  store i32 1, ptr %43, align 4
  br label %112

93:                                               ; preds = %84
  %94 = getelementptr inbounds [32 x i8], ptr %41, i64 0, i64 0
  %95 = load i64, ptr %42, align 8, !tbaa !9
  %96 = load ptr, ptr %23, align 8, !tbaa !5
  %97 = load ptr, ptr %24, align 8, !tbaa !5
  %98 = load ptr, ptr %25, align 8, !tbaa !5
  %99 = load ptr, ptr %28, align 8, !tbaa !5
  %100 = load ptr, ptr %29, align 8, !tbaa !5
  %101 = load ptr, ptr %30, align 8, !tbaa !5
  %102 = load ptr, ptr %31, align 8, !tbaa !5
  %103 = call i32 @cms_enced_content_info_decrypt_from_der(ptr noundef %40, ptr noundef %94, i64 noundef %95, ptr noundef %96, ptr noundef %97, ptr noundef %98, ptr noundef %99, ptr noundef %100, ptr noundef %101, ptr noundef %102, ptr noundef %38, ptr noundef %39)
  %104 = icmp ne i32 %103, 1
  br i1 %104, label %105, label %111

105:                                              ; preds = %93
  br label %106

106:                                              ; preds = %105
  %107 = load ptr, ptr @stderr, align 8, !tbaa !5
  %108 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %107, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 1626, ptr noundef @__FUNCTION__.cms_enveloped_data_decrypt_from_der) #4
  br label %109

109:                                              ; preds = %106
  br label %110

110:                                              ; preds = %109
  store i32 -1, ptr %17, align 4
  store i32 1, ptr %43, align 4
  br label %112

111:                                              ; preds = %93
  store i32 1, ptr %17, align 4
  store i32 1, ptr %43, align 4
  br label %112

112:                                              ; preds = %111, %110, %92, %77, %54
  call void @llvm.lifetime.end.p0(i64 8, ptr %42) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %41) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %40) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %39) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %38) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %37) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %36) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %35) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %34) #4
  %113 = load i32, ptr %17, align 4
  ret i32 %113
}

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 = { "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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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"

@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_enveloped_data_decrypt_from_der = external hidden unnamed_addr constant [36 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_enced_content_info_decrypt_from_der(ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare i32 @asn1_check(i32 noundef) local_unnamed_addr #3

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 2) i32 @cms_enveloped_data_decrypt_from_der(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, i64 noundef %4, ptr noundef %5, ptr noundef %6, ptr noundef %7, ptr nocapture noundef writeonly %8, ptr nocapture noundef writeonly %9, ptr noundef %10, ptr noundef %11, ptr noundef %12, ptr noundef %13, ptr noundef %14, ptr noundef %15) local_unnamed_addr #2 {
  %17 = alloca i32, align 4
  %18 = alloca ptr, align 8
  %19 = alloca i64, align 8
  %20 = alloca ptr, align 8
  %21 = alloca i64, align 8
  %22 = alloca i32, align 4
  %23 = alloca [32 x i8], align 16
  %24 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %17) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %18) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %19) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %20) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %21) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %22) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %23) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %24) #4
  %25 = call i32 @cms_enveloped_data_from_der(ptr noundef nonnull %17, ptr noundef nonnull %18, ptr noundef nonnull %19, ptr noundef nonnull %20, ptr noundef nonnull %21, ptr noundef %14, ptr noundef %15)
  %.not = icmp eq i32 %25, 1
  br i1 %.not, label %26, label %46

26:                                               ; preds = %16
  %27 = load i32, ptr %17, align 4, !tbaa !5
  %28 = icmp eq i32 %27, 1
  %29 = zext i1 %28 to i32
  %30 = call i32 @asn1_check(i32 noundef %29) #4
  %.not21 = icmp eq i32 %30, 1
  br i1 %.not21, label %31, label %46

31:                                               ; preds = %26
  %32 = load ptr, ptr %18, align 8, !tbaa !9
  store ptr %32, ptr %8, align 8, !tbaa !9
  %33 = load i64, ptr %19, align 8, !tbaa !11
  store i64 %33, ptr %9, align 8, !tbaa !11
  %.old1.not = icmp eq i64 %33, 0
  br i1 %.old1.not, label %.sink.split, label %.preheader

.preheader:                                       ; preds = %31, %36
  %34 = call i32 @cms_recipient_info_decrypt_from_der(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, i64 noundef %4, ptr noundef nonnull %23, ptr noundef nonnull %24, i64 noundef 32, ptr noundef nonnull %18, ptr noundef nonnull %19)
  %35 = icmp slt i32 %34, 0
  br i1 %35, label %.sink.split, label %36

36:                                               ; preds = %.preheader
  %37 = icmp eq i32 %34, 0
  %38 = load i64, ptr %19, align 8
  %39 = icmp ne i64 %38, 0
  %or.cond = select i1 %37, i1 %39, i1 false
  br i1 %or.cond, label %.preheader, label %40, !llvm.loop !13

40:                                               ; preds = %36
  br i1 %37, label %.sink.split, label %41

41:                                               ; preds = %40
  %42 = load i64, ptr %24, align 8, !tbaa !11
  %43 = call i32 @cms_enced_content_info_decrypt_from_der(ptr noundef nonnull %22, ptr noundef nonnull %23, i64 noundef %42, ptr noundef %5, ptr noundef %6, ptr noundef %7, ptr noundef %10, ptr noundef %11, ptr noundef %12, ptr noundef %13, ptr noundef nonnull %20, ptr noundef nonnull %21)
  %.not23 = icmp eq i32 %43, 1
  br i1 %.not23, label %46, label %.sink.split

.sink.split:                                      ; preds = %.preheader, %41, %40, %31
  %.sink28 = phi i32 [ 1616, %31 ], [ 1616, %40 ], [ 1626, %41 ], [ 1609, %.preheader ]
  %44 = load ptr, ptr @stderr, align 8, !tbaa !9
  %45 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %44, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef %.sink28, ptr noundef nonnull @__FUNCTION__.cms_enveloped_data_decrypt_from_der) #5
  br label %46

46:                                               ; preds = %.sink.split, %41, %16, %26
  %.019 = phi i32 [ -1, %26 ], [ -1, %16 ], [ 1, %41 ], [ -1, %.sink.split ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %24) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %23) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %22) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %21) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %20) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %19) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %18) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %17) #4
  ret i32 %.019
}

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 = { "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 }
attributes #5 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass