; 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"

%struct.SM4_KEY = type { [32 x i32] }

@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_enced_content_info_encrypt_to_der = external hidden unnamed_addr constant [38 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_to_der(i32 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_enced_content_info_encrypt_to_der(i32 noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, i64 noundef %4, i32 noundef %5, ptr noundef %6, i64 noundef %7, ptr noundef %8, i64 noundef %9, ptr noundef %10, i64 noundef %11, ptr noundef %12, ptr noundef %13) #2 {
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca ptr, align 8
  %18 = alloca i64, align 8
  %19 = alloca ptr, align 8
  %20 = alloca i64, align 8
  %21 = alloca i32, align 4
  %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 ptr, align 8
  %29 = alloca ptr, align 8
  %30 = alloca i32, align 4
  %31 = alloca %struct.SM4_KEY, align 4
  %32 = alloca ptr, align 8
  %33 = alloca i64, align 8
  %34 = alloca i32, align 4
  store i32 %0, ptr %16, align 4, !tbaa !5
  store ptr %1, ptr %17, align 8, !tbaa !9
  store i64 %2, ptr %18, align 8, !tbaa !11
  store ptr %3, ptr %19, align 8, !tbaa !9
  store i64 %4, ptr %20, align 8, !tbaa !11
  store i32 %5, ptr %21, align 4, !tbaa !5
  store ptr %6, ptr %22, align 8, !tbaa !9
  store i64 %7, ptr %23, align 8, !tbaa !11
  store ptr %8, ptr %24, align 8, !tbaa !9
  store i64 %9, ptr %25, align 8, !tbaa !11
  store ptr %10, ptr %26, align 8, !tbaa !9
  store i64 %11, ptr %27, align 8, !tbaa !11
  store ptr %12, ptr %28, align 8, !tbaa !9
  store ptr %13, ptr %29, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %30) #6
  call void @llvm.lifetime.start.p0(i64 128, ptr %31) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %32) #6
  store ptr null, ptr %32, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %33) #6
  store i64 100, ptr %33, align 8, !tbaa !11
  %35 = load i64, ptr %23, align 8, !tbaa !11
  %36 = add i64 32, %35
  %37 = call noalias ptr @malloc(i64 noundef %36) #7
  store ptr %37, ptr %32, align 8, !tbaa !9
  %38 = icmp ne ptr %37, null
  br i1 %38, label %45, label %39

39:                                               ; preds = %14
  br label %40

40:                                               ; preds = %39
  %41 = load ptr, ptr @stderr, align 8, !tbaa !9
  %42 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %41, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 351, ptr noundef @__FUNCTION__.cms_enced_content_info_encrypt_to_der) #6
  br label %43

43:                                               ; preds = %40
  br label %44

44:                                               ; preds = %43
  store i32 -1, ptr %15, align 4
  store i32 1, ptr %34, align 4
  br label %117

45:                                               ; preds = %14
  %46 = load i32, ptr %16, align 4, !tbaa !5
  %47 = icmp ne i32 %46, 98
  br i1 %47, label %54, label %48

48:                                               ; preds = %45
  %49 = load i64, ptr %18, align 8, !tbaa !11
  %50 = icmp ne i64 %49, 16
  br i1 %50, label %54, label %51

51:                                               ; preds = %48
  %52 = load i64, ptr %20, align 8, !tbaa !11
  %53 = icmp ne i64 %52, 16
  br i1 %53, label %54, label %65

54:                                               ; preds = %51, %48, %45
  br label %55

55:                                               ; preds = %54
  %56 = load ptr, ptr @stderr, align 8, !tbaa !9
  %57 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %56, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 358, ptr noundef @__FUNCTION__.cms_enced_content_info_encrypt_to_der) #6
  br label %58

58:                                               ; preds = %55
  br label %59

59:                                               ; preds = %58
  %60 = load ptr, ptr %32, align 8, !tbaa !9
  %61 = icmp ne ptr %60, null
  br i1 %61, label %62, label %64

62:                                               ; preds = %59
  %63 = load ptr, ptr %32, align 8, !tbaa !9
  call void @free(ptr noundef %63) #6
  br label %64

64:                                               ; preds = %62, %59
  store i32 -1, ptr %15, align 4
  store i32 1, ptr %34, align 4
  br label %117

65:                                               ; preds = %51
  %66 = load ptr, ptr %17, align 8, !tbaa !9
  call void @sm4_set_encrypt_key(ptr noundef %31, ptr noundef %66)
  %67 = load ptr, ptr %19, align 8, !tbaa !9
  %68 = load ptr, ptr %22, align 8, !tbaa !9
  %69 = load i64, ptr %23, align 8, !tbaa !11
  %70 = load ptr, ptr %32, align 8, !tbaa !9
  %71 = call i32 @sm4_cbc_padding_encrypt(ptr noundef %31, ptr noundef %67, ptr noundef %68, i64 noundef %69, ptr noundef %70, ptr noundef %33)
  %72 = icmp ne i32 %71, 1
  br i1 %72, label %73, label %84

73:                                               ; preds = %65
  %74 = load ptr, ptr %32, align 8, !tbaa !9
  %75 = icmp ne ptr %74, null
  br i1 %75, label %76, label %78

76:                                               ; preds = %73
  %77 = load ptr, ptr %32, align 8, !tbaa !9
  call void @free(ptr noundef %77) #6
  br label %78

78:                                               ; preds = %76, %73
  call void @llvm.memset.p0.i64(ptr align 4 %31, i8 0, i64 128, i1 false)
  br label %79

79:                                               ; preds = %78
  %80 = load ptr, ptr @stderr, align 8, !tbaa !9
  %81 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %80, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 368, ptr noundef @__FUNCTION__.cms_enced_content_info_encrypt_to_der) #6
  br label %82

82:                                               ; preds = %79
  br label %83

83:                                               ; preds = %82
  store i32 -1, ptr %15, align 4
  store i32 1, ptr %34, align 4
  br label %117

84:                                               ; preds = %65
  call void @llvm.memset.p0.i64(ptr align 4 %31, i8 0, i64 128, i1 false)
  %85 = load i32, ptr %21, align 4, !tbaa !5
  %86 = load i32, ptr %16, align 4, !tbaa !5
  %87 = load ptr, ptr %19, align 8, !tbaa !9
  %88 = load i64, ptr %20, align 8, !tbaa !11
  %89 = load ptr, ptr %32, align 8, !tbaa !9
  %90 = load i64, ptr %33, align 8, !tbaa !11
  %91 = load ptr, ptr %24, align 8, !tbaa !9
  %92 = load i64, ptr %25, align 8, !tbaa !11
  %93 = load ptr, ptr %26, align 8, !tbaa !9
  %94 = load i64, ptr %27, align 8, !tbaa !11
  %95 = load ptr, ptr %28, align 8, !tbaa !9
  %96 = load ptr, ptr %29, align 8, !tbaa !9
  %97 = call i32 @cms_enced_content_info_to_der(i32 noundef %85, i32 noundef %86, ptr noundef %87, i64 noundef %88, ptr noundef %89, i64 noundef %90, ptr noundef %91, i64 noundef %92, ptr noundef %93, i64 noundef %94, ptr noundef %95, ptr noundef %96)
  store i32 %97, ptr %30, align 4, !tbaa !5
  %98 = icmp ne i32 %97, 1
  br i1 %98, label %99, label %115

99:                                               ; preds = %84
  %100 = load ptr, ptr %32, align 8, !tbaa !9
  %101 = icmp ne ptr %100, null
  br i1 %101, label %102, label %104

102:                                              ; preds = %99
  %103 = load ptr, ptr %32, align 8, !tbaa !9
  call void @free(ptr noundef %103) #6
  br label %104

104:                                              ; preds = %102, %99
  %105 = load i32, ptr %30, align 4, !tbaa !5
  %106 = icmp slt i32 %105, 0
  br i1 %106, label %107, label %113

107:                                              ; preds = %104
  br label %108

108:                                              ; preds = %107
  %109 = load ptr, ptr @stderr, align 8, !tbaa !9
  %110 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %109, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 379, ptr noundef @__FUNCTION__.cms_enced_content_info_encrypt_to_der) #6
  br label %111

111:                                              ; preds = %108
  br label %112

112:                                              ; preds = %111
  br label %113

113:                                              ; preds = %112, %104
  %114 = load i32, ptr %30, align 4, !tbaa !5
  store i32 %114, ptr %15, align 4
  store i32 1, ptr %34, align 4
  br label %117

115:                                              ; preds = %84
  %116 = load ptr, ptr %32, align 8, !tbaa !9
  call void @free(ptr noundef %116) #6
  store i32 1, ptr %15, align 4
  store i32 1, ptr %34, align 4
  br label %117

117:                                              ; preds = %115, %113, %83, %64, %44
  call void @llvm.lifetime.end.p0(i64 8, ptr %33) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %32) #6
  call void @llvm.lifetime.end.p0(i64 128, ptr %31) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %30) #6
  %118 = load i32, ptr %15, align 4
  ret i32 %118
}

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #3

; Function Attrs: nounwind
declare void @free(ptr noundef) #1

declare void @sm4_set_encrypt_key(ptr noundef, ptr noundef) #4

declare i32 @sm4_cbc_padding_encrypt(ptr noundef, ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef) #4

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #5

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 allocsize(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 = { "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 #5 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { nounwind }
attributes #7 = { nounwind allocsize(0) }

!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}


; 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"

%struct.SM4_KEY = type { [32 x i32] }

@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_enced_content_info_encrypt_to_der = external hidden unnamed_addr constant [38 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_to_der(i32 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 i32 @cms_enced_content_info_encrypt_to_der(i32 noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, i64 noundef %4, i32 noundef %5, ptr noundef %6, i64 noundef %7, ptr noundef %8, i64 noundef %9, ptr noundef %10, i64 noundef %11, ptr noundef %12, ptr noundef %13) local_unnamed_addr #2 {
  %15 = alloca %struct.SM4_KEY, align 4
  %16 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %15) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %16) #7
  store i64 100, ptr %16, align 8, !tbaa !5
  %17 = add i64 %7, 32
  %18 = tail call noalias ptr @malloc(i64 noundef %17) #8
  %.not = icmp eq ptr %18, null
  br i1 %.not, label %19, label %22

19:                                               ; preds = %14
  %20 = load ptr, ptr @stderr, align 8, !tbaa !9
  %21 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %20, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 351, ptr noundef nonnull @__FUNCTION__.cms_enced_content_info_encrypt_to_der) #9
  br label %42

22:                                               ; preds = %14
  %23 = icmp ne i32 %0, 98
  %24 = icmp ne i64 %2, 16
  %or.cond = or i1 %23, %24
  %25 = icmp ne i64 %4, 16
  %or.cond3 = or i1 %or.cond, %25
  br i1 %or.cond3, label %26, label %29

26:                                               ; preds = %22
  %27 = load ptr, ptr @stderr, align 8, !tbaa !9
  %28 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %27, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 358, ptr noundef nonnull @__FUNCTION__.cms_enced_content_info_encrypt_to_der) #9
  tail call void @free(ptr noundef nonnull %18) #7
  br label %42

29:                                               ; preds = %22
  call void @sm4_set_encrypt_key(ptr noundef nonnull %15, ptr noundef %1) #7
  %30 = call i32 @sm4_cbc_padding_encrypt(ptr noundef nonnull %15, ptr noundef %3, ptr noundef %6, i64 noundef %7, ptr noundef nonnull %18, ptr noundef nonnull %16) #7
  %.not36 = icmp eq i32 %30, 1
  br i1 %.not36, label %34, label %31

31:                                               ; preds = %29
  call void @free(ptr noundef nonnull %18) #7
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(128) %15, i8 0, i64 128, i1 false)
  %32 = load ptr, ptr @stderr, align 8, !tbaa !9
  %33 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %32, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 368, ptr noundef nonnull @__FUNCTION__.cms_enced_content_info_encrypt_to_der) #9
  br label %42

34:                                               ; preds = %29
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(128) %15, i8 0, i64 128, i1 false)
  %35 = load i64, ptr %16, align 8, !tbaa !5
  %36 = call i32 @cms_enced_content_info_to_der(i32 noundef %5, i32 noundef 98, ptr noundef %3, i64 noundef 16, ptr noundef nonnull %18, i64 noundef %35, ptr noundef %8, i64 noundef %9, ptr noundef %10, i64 noundef %11, ptr noundef %12, ptr noundef %13)
  %.not37 = icmp eq i32 %36, 1
  call void @free(ptr noundef nonnull %18) #7
  br i1 %.not37, label %42, label %37

37:                                               ; preds = %34
  %38 = icmp slt i32 %36, 0
  br i1 %38, label %39, label %42

39:                                               ; preds = %37
  %40 = load ptr, ptr @stderr, align 8, !tbaa !9
  %41 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %40, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 379, ptr noundef nonnull @__FUNCTION__.cms_enced_content_info_encrypt_to_der) #9
  br label %42

42:                                               ; preds = %34, %37, %39, %31, %26, %19
  %.0 = phi i32 [ -1, %26 ], [ -1, %31 ], [ -1, %19 ], [ %36, %39 ], [ %36, %37 ], [ 1, %34 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %16) #7
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %15) #7
  ret i32 %.0
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #4

declare void @sm4_set_encrypt_key(ptr noundef, ptr noundef) local_unnamed_addr #5

declare i32 @sm4_cbc_padding_encrypt(ptr noundef, ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #5

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #6

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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 #5 = { "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 #6 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #7 = { nounwind }
attributes #8 = { nounwind allocsize(0) }
attributes #9 = { 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: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass