; 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_digest_algors_from_der = external hidden unnamed_addr constant [27 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

declare i32 @asn1_nonempty_type_from_der(i32 noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #2

declare i32 @x509_digest_algor_from_der(ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @cms_digest_algors_from_der(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, ptr noundef %4) #3 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  %15 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i64 %2, ptr %9, align 8, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %16 = load ptr, ptr %10, align 8, !tbaa !5
  %17 = load ptr, ptr %11, align 8, !tbaa !5
  %18 = call i32 @asn1_nonempty_type_from_der(i32 noundef 49, ptr noundef %13, ptr noundef %14, ptr noundef %16, ptr noundef %17)
  store i32 %18, ptr %12, align 4, !tbaa !11
  %19 = icmp ne i32 %18, 1
  br i1 %19, label %20, label %31

20:                                               ; preds = %5
  %21 = load i32, ptr %12, align 4, !tbaa !11
  %22 = icmp slt i32 %21, 0
  br i1 %22, label %23, label %29

23:                                               ; preds = %20
  br label %24

24:                                               ; preds = %23
  %25 = load ptr, ptr @stderr, align 8, !tbaa !5
  %26 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %25, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 897, ptr noundef @__FUNCTION__.cms_digest_algors_from_der) #4
  br label %27

27:                                               ; preds = %24
  br label %28

28:                                               ; preds = %27
  br label %29

29:                                               ; preds = %28, %20
  %30 = load i32, ptr %12, align 4, !tbaa !11
  store i32 %30, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %64

31:                                               ; preds = %5
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  store i64 0, ptr %32, align 8, !tbaa !9
  br label %33

33:                                               ; preds = %57, %31
  %34 = load i64, ptr %14, align 8, !tbaa !9
  %35 = icmp ne i64 %34, 0
  br i1 %35, label %36, label %63

36:                                               ; preds = %33
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = load i64, ptr %37, align 8, !tbaa !9
  %39 = load i64, ptr %9, align 8, !tbaa !9
  %40 = icmp ugt i64 %38, %39
  br i1 %40, label %41, label %47

41:                                               ; preds = %36
  br label %42

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

45:                                               ; preds = %42
  br label %46

46:                                               ; preds = %45
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %64

47:                                               ; preds = %36
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = call i32 @x509_digest_algor_from_der(ptr noundef %48, ptr noundef %13, ptr noundef %14)
  %50 = icmp ne i32 %49, 1
  br i1 %50, label %51, label %57

51:                                               ; preds = %47
  br label %52

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

55:                                               ; preds = %52
  br label %56

56:                                               ; preds = %55
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %64

57:                                               ; preds = %47
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = getelementptr inbounds i32, ptr %58, i32 1
  store ptr %59, ptr %7, align 8, !tbaa !5
  %60 = load ptr, ptr %8, align 8, !tbaa !5
  %61 = load i64, ptr %60, align 8, !tbaa !9
  %62 = add i64 %61, 1
  store i64 %62, ptr %60, align 8, !tbaa !9
  br label %33, !llvm.loop !13

63:                                               ; preds = %33
  store i32 1, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %64

64:                                               ; preds = %63, %56, %46, %29
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  %65 = load i32, ptr %6, align 4
  ret i32 %65
}

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 = { "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 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 #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_digest_algors_from_der = external hidden unnamed_addr constant [27 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

declare i32 @asn1_nonempty_type_from_der(i32 noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare i32 @x509_digest_algor_from_der(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local i32 @cms_digest_algors_from_der(ptr noundef %0, ptr nocapture noundef %1, i64 noundef %2, ptr noundef %3, ptr noundef %4) local_unnamed_addr #3 {
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #4
  %8 = call i32 @asn1_nonempty_type_from_der(i32 noundef 49, ptr noundef nonnull %6, ptr noundef nonnull %7, ptr noundef %3, ptr noundef %4) #4
  %.not = icmp eq i32 %8, 1
  br i1 %.not, label %.preheader, label %10

.preheader:                                       ; preds = %5
  store i64 0, ptr %1, align 8, !tbaa !5
  %9 = load i64, ptr %7, align 8, !tbaa !5
  %.not1214 = icmp eq i64 %9, 0
  br i1 %.not1214, label %.loopexit, label %.lr.ph

10:                                               ; preds = %5
  %11 = icmp slt i32 %8, 0
  br i1 %11, label %.loopexit.sink.split, label %.loopexit

.lr.ph:                                           ; preds = %.preheader, %15
  %.01016 = phi ptr [ %16, %15 ], [ %0, %.preheader ]
  %storemerge15 = phi i64 [ %18, %15 ], [ 0, %.preheader ]
  %12 = icmp ugt i64 %storemerge15, %2
  br i1 %12, label %.loopexit.sink.split, label %13

13:                                               ; preds = %.lr.ph
  %14 = call i32 @x509_digest_algor_from_der(ptr noundef %.01016, ptr noundef nonnull %6, ptr noundef nonnull %7) #4
  %.not13 = icmp eq i32 %14, 1
  br i1 %.not13, label %15, label %.loopexit.sink.split

15:                                               ; preds = %13
  %16 = getelementptr inbounds i8, ptr %.01016, i64 4
  %17 = load i64, ptr %1, align 8, !tbaa !5
  %18 = add i64 %17, 1
  store i64 %18, ptr %1, align 8, !tbaa !5
  %19 = load i64, ptr %7, align 8, !tbaa !5
  %.not12 = icmp eq i64 %19, 0
  br i1 %.not12, label %.loopexit, label %.lr.ph, !llvm.loop !9

.loopexit.sink.split:                             ; preds = %13, %.lr.ph, %10
  %.sink17 = phi i32 [ 897, %10 ], [ 904, %.lr.ph ], [ 908, %13 ]
  %.0.ph = phi i32 [ %8, %10 ], [ -1, %.lr.ph ], [ -1, %13 ]
  %20 = load ptr, ptr @stderr, align 8, !tbaa !11
  %21 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %20, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef %.sink17, ptr noundef nonnull @__FUNCTION__.cms_digest_algors_from_der) #5
  br label %.loopexit

.loopexit:                                        ; preds = %15, %.loopexit.sink.split, %.preheader, %10
  %.0 = phi i32 [ %8, %10 ], [ 1, %.preheader ], [ %.0.ph, %.loopexit.sink.split ], [ 1, %15 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #4
  ret i32 %.0
}

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


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