; 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_decrypt_from_der = external hidden unnamed_addr constant [40 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_from_der(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #2

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

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

42:                                               ; preds = %12
  %43 = load ptr, ptr %14, align 8, !tbaa !5
  %44 = load i32, ptr %43, align 4, !tbaa !11
  %45 = icmp eq i32 %44, 98
  %46 = zext i1 %45 to i32
  %47 = call i32 @asn1_check(i32 noundef %46)
  %48 = icmp ne i32 %47, 1
  br i1 %48, label %61, label %49

49:                                               ; preds = %42
  %50 = load i64, ptr %28, align 8, !tbaa !9
  %51 = icmp eq i64 %50, 16
  %52 = zext i1 %51 to i32
  %53 = call i32 @asn1_check(i32 noundef %52)
  %54 = icmp ne i32 %53, 1
  br i1 %54, label %61, label %55

55:                                               ; preds = %49
  %56 = load i64, ptr %16, align 8, !tbaa !9
  %57 = icmp eq i64 %56, 16
  %58 = zext i1 %57 to i32
  %59 = call i32 @asn1_check(i32 noundef %58)
  %60 = icmp ne i32 %59, 1
  br i1 %60, label %61, label %67

61:                                               ; preds = %55, %49, %42, %12
  br label %62

62:                                               ; preds = %61
  %63 = load ptr, ptr @stderr, align 8, !tbaa !5
  %64 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %63, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 410, ptr noundef @__FUNCTION__.cms_enced_content_info_decrypt_from_der) #5
  br label %65

65:                                               ; preds = %62
  br label %66

66:                                               ; preds = %65
  store i32 -1, ptr %13, align 4
  store i32 1, ptr %31, align 4
  br label %78

67:                                               ; preds = %55
  %68 = load ptr, ptr %15, align 8, !tbaa !5
  call void @sm4_set_decrypt_key(ptr noundef %26, ptr noundef %68)
  %69 = load ptr, ptr %27, align 8, !tbaa !5
  %70 = load ptr, ptr %29, align 8, !tbaa !5
  %71 = load i64, ptr %30, align 8, !tbaa !9
  %72 = load ptr, ptr %18, align 8, !tbaa !5
  %73 = load ptr, ptr %19, align 8, !tbaa !5
  %74 = call i32 @sm4_cbc_padding_decrypt(ptr noundef %26, ptr noundef %69, ptr noundef %70, i64 noundef %71, ptr noundef %72, ptr noundef %73)
  %75 = icmp ne i32 %74, 1
  br i1 %75, label %76, label %77

76:                                               ; preds = %67
  call void @llvm.memset.p0.i64(ptr align 4 %26, i8 0, i64 128, i1 false)
  store i32 -1, ptr %13, align 4
  store i32 1, ptr %31, align 4
  br label %78

77:                                               ; preds = %67
  call void @llvm.memset.p0.i64(ptr align 4 %26, i8 0, i64 128, i1 false)
  store i32 1, ptr %13, align 4
  store i32 1, ptr %31, align 4
  br label %78

78:                                               ; preds = %77, %76, %66
  call void @llvm.lifetime.end.p0(i64 8, ptr %30) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %29) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %28) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %27) #5
  call void @llvm.lifetime.end.p0(i64 128, ptr %26) #5
  %79 = load i32, ptr %13, align 4
  ret i32 %79
}

declare i32 @asn1_check(i32 noundef) #4

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

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

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = { 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"

%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_decrypt_from_der = external hidden unnamed_addr constant [40 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_from_der(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, 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_enced_content_info_decrypt_from_der(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5, ptr noundef %6, ptr noundef %7, ptr noundef %8, ptr noundef %9, ptr noundef %10, ptr noundef %11) local_unnamed_addr #2 {
  %13 = alloca %struct.SM4_KEY, align 4
  %14 = alloca ptr, align 8
  %15 = alloca i64, align 8
  %16 = alloca ptr, align 8
  %17 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %13) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %14) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %15) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %16) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %17) #4
  %18 = call i32 @cms_enced_content_info_from_der(ptr noundef %3, ptr noundef %0, ptr noundef nonnull %14, ptr noundef nonnull %15, ptr noundef nonnull %16, ptr noundef nonnull %17, ptr noundef %6, ptr noundef %7, ptr noundef %8, ptr noundef %9, ptr noundef %10, ptr noundef %11)
  %.not = icmp eq i32 %18, 1
  br i1 %.not, label %19, label %33

19:                                               ; preds = %12
  %20 = load i32, ptr %0, align 4, !tbaa !5
  %21 = icmp eq i32 %20, 98
  %22 = zext i1 %21 to i32
  %23 = call i32 @asn1_check(i32 noundef %22) #4
  %.not13 = icmp eq i32 %23, 1
  br i1 %.not13, label %24, label %33

24:                                               ; preds = %19
  %25 = load i64, ptr %15, align 8, !tbaa !9
  %26 = icmp eq i64 %25, 16
  %27 = zext i1 %26 to i32
  %28 = call i32 @asn1_check(i32 noundef %27) #4
  %.not14 = icmp eq i32 %28, 1
  br i1 %.not14, label %29, label %33

29:                                               ; preds = %24
  %30 = icmp eq i64 %2, 16
  %31 = zext i1 %30 to i32
  %32 = call i32 @asn1_check(i32 noundef %31) #4
  %.not15 = icmp eq i32 %32, 1
  br i1 %.not15, label %36, label %33

33:                                               ; preds = %12, %19, %24, %29
  %34 = load ptr, ptr @stderr, align 8, !tbaa !11
  %35 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %34, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 410, ptr noundef nonnull @__FUNCTION__.cms_enced_content_info_decrypt_from_der) #5
  br label %41

36:                                               ; preds = %29
  call void @sm4_set_decrypt_key(ptr noundef nonnull %13, ptr noundef %1) #4
  %37 = load ptr, ptr %14, align 8, !tbaa !11
  %38 = load ptr, ptr %16, align 8, !tbaa !11
  %39 = load i64, ptr %17, align 8, !tbaa !9
  %40 = call i32 @sm4_cbc_padding_decrypt(ptr noundef nonnull %13, ptr noundef %37, ptr noundef %38, i64 noundef %39, ptr noundef %4, ptr noundef %5) #4
  %.not16 = icmp eq i32 %40, 1
  %. = select i1 %.not16, i32 1, i32 -1
  br label %41

41:                                               ; preds = %36, %33
  %.0 = phi i32 [ -1, %33 ], [ %., %36 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %17) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %16) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %14) #4
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %13) #4
  ret i32 %.0
}

declare i32 @asn1_check(i32 noundef) local_unnamed_addr #3

declare void @sm4_set_decrypt_key(ptr noundef, ptr noundef) local_unnamed_addr #3

declare i32 @sm4_cbc_padding_decrypt(ptr noundef, ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr 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 = !{!"int", !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 = !{!"any pointer", !7, i64 0}


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