; 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_set_key_agreement_info = 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

; 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_key_agreement_info_to_der(i32 noundef, ptr noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @cms_set_key_agreement_info(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, i64 noundef %4, ptr noundef %5, i64 noundef %6) #2 {
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i64, align 8
  %16 = alloca i32, align 4
  %17 = alloca i64, align 8
  %18 = alloca i32, align 4
  %19 = alloca [1 x i8], align 1
  store ptr %0, ptr %9, align 8, !tbaa !5
  store ptr %1, ptr %10, align 8, !tbaa !5
  store ptr %2, ptr %11, align 8, !tbaa !5
  store ptr %3, ptr %12, align 8, !tbaa !5
  store i64 %4, ptr %13, align 8, !tbaa !9
  store ptr %5, ptr %14, align 8, !tbaa !5
  store i64 %6, ptr %15, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  store i32 123, ptr %16, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #3
  store i64 0, ptr %17, align 8, !tbaa !9
  %20 = load ptr, ptr %11, align 8, !tbaa !5
  %21 = load ptr, ptr %12, align 8, !tbaa !5
  %22 = load i64, ptr %13, align 8, !tbaa !9
  %23 = load ptr, ptr %14, align 8, !tbaa !5
  %24 = load i64, ptr %15, align 8, !tbaa !9
  %25 = call i32 @cms_key_agreement_info_to_der(i32 noundef 1, ptr noundef %20, ptr noundef %21, i64 noundef %22, ptr noundef %23, i64 noundef %24, ptr noundef null, ptr noundef %17)
  %26 = icmp ne i32 %25, 1
  br i1 %26, label %27, label %33

27:                                               ; preds = %7
  br label %28

28:                                               ; preds = %27
  %29 = load ptr, ptr @stderr, align 8, !tbaa !5
  %30 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %29, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 2427, ptr noundef @__FUNCTION__.cms_set_key_agreement_info) #3
  br label %31

31:                                               ; preds = %28
  br label %32

32:                                               ; preds = %31
  store i32 -1, ptr %8, align 4
  store i32 1, ptr %18, align 4
  br label %74

33:                                               ; preds = %7
  %34 = load ptr, ptr %10, align 8, !tbaa !5
  store i64 0, ptr %34, align 8, !tbaa !9
  %35 = load ptr, ptr %9, align 8, !tbaa !5
  %36 = icmp ne ptr %35, null
  br i1 %36, label %52, label %37

37:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 1, ptr %19) #3
  %38 = load i32, ptr %16, align 4, !tbaa !11
  %39 = getelementptr inbounds [1 x i8], ptr %19, i64 0, i64 0
  %40 = load i64, ptr %17, align 8, !tbaa !9
  %41 = load ptr, ptr %10, align 8, !tbaa !5
  %42 = call i32 @cms_content_info_to_der(i32 noundef %38, ptr noundef %39, i64 noundef %40, ptr noundef null, ptr noundef %41)
  %43 = icmp ne i32 %42, 1
  br i1 %43, label %44, label %50

44:                                               ; preds = %37
  br label %45

45:                                               ; preds = %44
  %46 = load ptr, ptr @stderr, align 8, !tbaa !5
  %47 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %46, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 2434, ptr noundef @__FUNCTION__.cms_set_key_agreement_info) #3
  br label %48

48:                                               ; preds = %45
  br label %49

49:                                               ; preds = %48
  store i32 -1, ptr %8, align 4
  store i32 1, ptr %18, align 4
  br label %51

50:                                               ; preds = %37
  store i32 1, ptr %8, align 4
  store i32 1, ptr %18, align 4
  br label %51

51:                                               ; preds = %50, %49
  call void @llvm.lifetime.end.p0(i64 1, ptr %19) #3
  br label %74

52:                                               ; preds = %33
  %53 = load i32, ptr %16, align 4, !tbaa !11
  %54 = load i64, ptr %17, align 8, !tbaa !9
  %55 = load ptr, ptr %10, align 8, !tbaa !5
  %56 = call i32 @cms_content_info_header_to_der(i32 noundef %53, i64 noundef %54, ptr noundef %9, ptr noundef %55)
  %57 = icmp ne i32 %56, 1
  br i1 %57, label %67, label %58

58:                                               ; preds = %52
  %59 = load ptr, ptr %11, align 8, !tbaa !5
  %60 = load ptr, ptr %12, align 8, !tbaa !5
  %61 = load i64, ptr %13, align 8, !tbaa !9
  %62 = load ptr, ptr %14, align 8, !tbaa !5
  %63 = load i64, ptr %15, align 8, !tbaa !9
  %64 = load ptr, ptr %10, align 8, !tbaa !5
  %65 = call i32 @cms_key_agreement_info_to_der(i32 noundef 1, ptr noundef %59, ptr noundef %60, i64 noundef %61, ptr noundef %62, i64 noundef %63, ptr noundef %9, ptr noundef %64)
  %66 = icmp ne i32 %65, 1
  br i1 %66, label %67, label %73

67:                                               ; preds = %58, %52
  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 2442, ptr noundef @__FUNCTION__.cms_set_key_agreement_info) #3
  br label %71

71:                                               ; preds = %68
  br label %72

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

73:                                               ; preds = %58
  store i32 1, ptr %8, align 4
  store i32 1, ptr %18, align 4
  br label %74

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

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_set_key_agreement_info = 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

; 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_key_agreement_info_to_der(i32 noundef, ptr 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_set_key_agreement_info(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, i64 noundef %4, ptr noundef %5, i64 noundef %6) local_unnamed_addr #2 {
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca [1 x i8], align 1
  store ptr %0, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %9) #3
  store i64 0, ptr %9, align 8, !tbaa !9
  %11 = call i32 @cms_key_agreement_info_to_der(i32 noundef 1, ptr noundef %2, ptr noundef %3, i64 noundef %4, ptr noundef %5, i64 noundef %6, ptr noundef null, ptr noundef nonnull %9)
  %.not = icmp eq i32 %11, 1
  br i1 %.not, label %15, label %12

12:                                               ; preds = %7
  %13 = load ptr, ptr @stderr, align 8, !tbaa !5
  %14 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %13, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 2427, ptr noundef nonnull @__FUNCTION__.cms_set_key_agreement_info) #4
  br label %31

15:                                               ; preds = %7
  store i64 0, ptr %1, align 8, !tbaa !9
  %.not16 = icmp eq ptr %0, null
  br i1 %.not16, label %16, label %23

16:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %10) #3
  %17 = load i64, ptr %9, align 8, !tbaa !9
  %18 = call i32 @cms_content_info_to_der(i32 noundef 123, ptr noundef nonnull %10, i64 noundef %17, ptr noundef null, ptr noundef nonnull %1)
  %.not17 = icmp eq i32 %18, 1
  br i1 %.not17, label %22, label %19

19:                                               ; preds = %16
  %20 = load ptr, ptr @stderr, align 8, !tbaa !5
  %21 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %20, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 2434, ptr noundef nonnull @__FUNCTION__.cms_set_key_agreement_info) #4
  br label %22

22:                                               ; preds = %16, %19
  %.0 = phi i32 [ -1, %19 ], [ 1, %16 ]
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %10) #3
  br label %31

23:                                               ; preds = %15
  %24 = load i64, ptr %9, align 8, !tbaa !9
  %25 = call i32 @cms_content_info_header_to_der(i32 noundef 123, i64 noundef %24, ptr noundef nonnull %8, ptr noundef nonnull %1)
  %.not18 = icmp eq i32 %25, 1
  br i1 %.not18, label %26, label %28

26:                                               ; preds = %23
  %27 = call i32 @cms_key_agreement_info_to_der(i32 noundef 1, ptr noundef %2, ptr noundef %3, i64 noundef %4, ptr noundef %5, i64 noundef %6, ptr noundef nonnull %8, ptr noundef nonnull %1)
  %.not19 = icmp eq i32 %27, 1
  br i1 %.not19, label %31, label %28

28:                                               ; preds = %23, %26
  %29 = load ptr, ptr @stderr, align 8, !tbaa !5
  %30 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %29, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 2442, ptr noundef nonnull @__FUNCTION__.cms_set_key_agreement_info) #4
  br label %31

31:                                               ; preds = %26, %28, %22, %12
  %.1 = phi i32 [ -1, %12 ], [ -1, %28 ], [ %.0, %22 ], [ 1, %26 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %9) #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