; 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_signer_infos_add_signer_info = external hidden unnamed_addr constant [33 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_sign_to_der(ptr noundef, ptr 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_signer_infos_add_signer_info(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5, i64 noundef %6, ptr noundef %7, i64 noundef %8, ptr noundef %9, i64 noundef %10, ptr noundef %11, i64 noundef %12) #2 {
  %14 = alloca i32, align 4
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca i64, align 8
  %18 = alloca ptr, align 8
  %19 = alloca ptr, 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 i64, align 8
  %26 = alloca ptr, align 8
  %27 = alloca i64, align 8
  %28 = alloca i64, align 8
  %29 = alloca i32, align 4
  store ptr %0, ptr %15, align 8, !tbaa !5
  store ptr %1, ptr %16, align 8, !tbaa !5
  store i64 %2, ptr %17, align 8, !tbaa !9
  store ptr %3, ptr %18, align 8, !tbaa !5
  store ptr %4, ptr %19, align 8, !tbaa !5
  store ptr %5, ptr %20, align 8, !tbaa !5
  store i64 %6, ptr %21, align 8, !tbaa !9
  store ptr %7, ptr %22, align 8, !tbaa !5
  store i64 %8, ptr %23, align 8, !tbaa !9
  store ptr %9, ptr %24, align 8, !tbaa !5
  store i64 %10, ptr %25, align 8, !tbaa !9
  store ptr %11, ptr %26, align 8, !tbaa !5
  store i64 %12, ptr %27, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %28) #4
  %30 = load ptr, ptr %16, align 8, !tbaa !5
  %31 = load i64, ptr %30, align 8, !tbaa !9
  store i64 %31, ptr %28, align 8, !tbaa !9
  %32 = load ptr, ptr %16, align 8, !tbaa !5
  %33 = load i64, ptr %32, align 8, !tbaa !9
  %34 = load ptr, ptr %15, align 8, !tbaa !5
  %35 = getelementptr inbounds i8, ptr %34, i64 %33
  store ptr %35, ptr %15, align 8, !tbaa !5
  %36 = load ptr, ptr %18, align 8, !tbaa !5
  %37 = load ptr, ptr %19, align 8, !tbaa !5
  %38 = load ptr, ptr %20, align 8, !tbaa !5
  %39 = load i64, ptr %21, align 8, !tbaa !9
  %40 = load ptr, ptr %22, align 8, !tbaa !5
  %41 = load i64, ptr %23, align 8, !tbaa !9
  %42 = load ptr, ptr %24, align 8, !tbaa !5
  %43 = load i64, ptr %25, align 8, !tbaa !9
  %44 = load ptr, ptr %26, align 8, !tbaa !5
  %45 = load i64, ptr %27, align 8, !tbaa !9
  %46 = call i32 @cms_signer_info_sign_to_der(ptr noundef %36, ptr noundef %37, ptr noundef %38, i64 noundef %39, ptr noundef %40, i64 noundef %41, ptr noundef %42, i64 noundef %43, ptr noundef %44, i64 noundef %45, ptr noundef null, ptr noundef %28)
  %47 = icmp ne i32 %46, 1
  br i1 %47, label %67, label %48

48:                                               ; preds = %13
  %49 = load i64, ptr %28, align 8, !tbaa !9
  %50 = load i64, ptr %17, align 8, !tbaa !9
  %51 = call i32 @asn1_length_le(i64 noundef %49, i64 noundef %50)
  %52 = icmp ne i32 %51, 1
  br i1 %52, label %67, label %53

53:                                               ; preds = %48
  %54 = load ptr, ptr %18, align 8, !tbaa !5
  %55 = load ptr, ptr %19, align 8, !tbaa !5
  %56 = load ptr, ptr %20, align 8, !tbaa !5
  %57 = load i64, ptr %21, align 8, !tbaa !9
  %58 = load ptr, ptr %22, align 8, !tbaa !5
  %59 = load i64, ptr %23, align 8, !tbaa !9
  %60 = load ptr, ptr %24, align 8, !tbaa !5
  %61 = load i64, ptr %25, align 8, !tbaa !9
  %62 = load ptr, ptr %26, align 8, !tbaa !5
  %63 = load i64, ptr %27, align 8, !tbaa !9
  %64 = load ptr, ptr %16, align 8, !tbaa !5
  %65 = call i32 @cms_signer_info_sign_to_der(ptr noundef %54, ptr 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 %15, ptr noundef %64)
  %66 = icmp ne i32 %65, 1
  br i1 %66, label %67, label %73

67:                                               ; preds = %53, %48, %13
  br label %68

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

71:                                               ; preds = %68
  br label %72

72:                                               ; preds = %71
  store i32 -1, ptr %14, align 4
  store i32 1, ptr %29, align 4
  br label %74

73:                                               ; preds = %53
  store i32 1, ptr %14, align 4
  store i32 1, ptr %29, align 4
  br label %74

74:                                               ; preds = %73, %72
  call void @llvm.lifetime.end.p0(i64 8, ptr %28) #4
  %75 = load i32, ptr %14, align 4
  ret i32 %75
}

declare i32 @asn1_length_le(i64 noundef, i64 noundef) #3

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}


; 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_signer_infos_add_signer_info = external hidden unnamed_addr constant [33 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_sign_to_der(ptr noundef, ptr 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_signer_infos_add_signer_info(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5, i64 noundef %6, ptr noundef %7, i64 noundef %8, ptr noundef %9, i64 noundef %10, ptr noundef %11, i64 noundef %12) local_unnamed_addr #2 {
  %14 = alloca ptr, align 8
  %15 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %15) #4
  %16 = load i64, ptr %1, align 8, !tbaa !5
  store i64 %16, ptr %15, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %0, i64 %16
  store ptr %17, ptr %14, align 8, !tbaa !9
  %18 = call i32 @cms_signer_info_sign_to_der(ptr noundef %3, ptr noundef %4, ptr noundef %5, i64 noundef %6, ptr noundef %7, i64 noundef %8, ptr noundef %9, i64 noundef %10, ptr noundef %11, i64 noundef %12, ptr noundef null, ptr noundef nonnull %15)
  %.not = icmp eq i32 %18, 1
  br i1 %.not, label %19, label %24

19:                                               ; preds = %13
  %20 = load i64, ptr %15, align 8, !tbaa !5
  %21 = call i32 @asn1_length_le(i64 noundef %20, i64 noundef %2) #4
  %.not24 = icmp eq i32 %21, 1
  br i1 %.not24, label %22, label %24

22:                                               ; preds = %19
  %23 = call i32 @cms_signer_info_sign_to_der(ptr noundef %3, ptr noundef %4, ptr noundef %5, i64 noundef %6, ptr noundef %7, i64 noundef %8, ptr noundef %9, i64 noundef %10, ptr noundef %11, i64 noundef %12, ptr noundef nonnull %14, ptr noundef nonnull %1)
  %.not25 = icmp eq i32 %23, 1
  br i1 %.not25, label %27, label %24

24:                                               ; preds = %13, %19, %22
  %25 = load ptr, ptr @stderr, align 8, !tbaa !9
  %26 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %25, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 842, ptr noundef nonnull @__FUNCTION__.cms_signer_infos_add_signer_info) #5
  br label %27

27:                                               ; preds = %22, %24
  %.0 = phi i32 [ -1, %24 ], [ 1, %22 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %15) #4
  ret i32 %.0
}

declare i32 @asn1_length_le(i64 noundef, i64 noundef) local_unnamed_addr #3

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 = !{!"long", !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}


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