; LLVM IR from guanzhi/GmSSL :: src (sm9_enc)

; 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 [61 x i8], align 1
@__FUNCTION__.sm9_ciphertext_to_der = external hidden unnamed_addr constant [22 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

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

; 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
define dso_local i32 @sm9_ciphertext_to_der(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5) #3 {
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %15 = alloca [65 x i8], align 16
  %16 = alloca i64, align 8
  %17 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store i64 %2, ptr %10, align 8, !tbaa !9
  store ptr %3, ptr %11, align 8, !tbaa !5
  store ptr %4, ptr %12, align 8, !tbaa !5
  store ptr %5, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  store i32 0, ptr %14, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 65, ptr %15) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  store i64 0, ptr %16, align 8, !tbaa !9
  %18 = load ptr, ptr %8, align 8, !tbaa !5
  %19 = getelementptr inbounds [65 x i8], ptr %15, i64 0, i64 0
  %20 = call i32 @sm9_z256_point_to_uncompressed_octets(ptr noundef %18, ptr noundef %19)
  %21 = icmp ne i32 %20, 1
  br i1 %21, label %22, label %28

22:                                               ; preds = %6
  br label %23

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

26:                                               ; preds = %23
  br label %27

27:                                               ; preds = %26
  store i32 -1, ptr %7, align 4
  store i32 1, ptr %17, align 4
  br label %83

28:                                               ; preds = %6
  %29 = load i32, ptr %14, align 4, !tbaa !11
  %30 = call i32 @asn1_int_to_der_ex(i32 noundef 2, i32 noundef %29, ptr noundef null, ptr noundef %16)
  %31 = icmp ne i32 %30, 1
  br i1 %31, label %76, label %32

32:                                               ; preds = %28
  %33 = getelementptr inbounds [65 x i8], ptr %15, i64 0, i64 0
  %34 = call i32 @asn1_bit_octets_to_der_ex(i32 noundef 3, ptr noundef %33, i64 noundef 65, ptr noundef null, ptr noundef %16)
  %35 = icmp ne i32 %34, 1
  br i1 %35, label %76, label %36

36:                                               ; preds = %32
  %37 = load ptr, ptr %11, align 8, !tbaa !5
  %38 = call i32 @asn1_type_to_der(i32 noundef 4, ptr noundef %37, i64 noundef 32, ptr noundef null, ptr noundef %16)
  %39 = icmp ne i32 %38, 1
  br i1 %39, label %76, label %40

40:                                               ; preds = %36
  %41 = load ptr, ptr %9, align 8, !tbaa !5
  %42 = load i64, ptr %10, align 8, !tbaa !9
  %43 = call i32 @asn1_type_to_der(i32 noundef 4, ptr noundef %41, i64 noundef %42, ptr noundef null, ptr noundef %16)
  %44 = icmp ne i32 %43, 1
  br i1 %44, label %76, label %45

45:                                               ; preds = %40
  %46 = load i64, ptr %16, align 8, !tbaa !9
  %47 = load ptr, ptr %12, align 8, !tbaa !5
  %48 = load ptr, ptr %13, align 8, !tbaa !5
  %49 = call i32 @asn1_header_to_der(i32 noundef 48, i64 noundef %46, ptr noundef %47, ptr noundef %48)
  %50 = icmp ne i32 %49, 1
  br i1 %50, label %76, label %51

51:                                               ; preds = %45
  %52 = load i32, ptr %14, align 4, !tbaa !11
  %53 = load ptr, ptr %12, align 8, !tbaa !5
  %54 = load ptr, ptr %13, align 8, !tbaa !5
  %55 = call i32 @asn1_int_to_der_ex(i32 noundef 2, i32 noundef %52, ptr noundef %53, ptr noundef %54)
  %56 = icmp ne i32 %55, 1
  br i1 %56, label %76, label %57

57:                                               ; preds = %51
  %58 = getelementptr inbounds [65 x i8], ptr %15, i64 0, i64 0
  %59 = load ptr, ptr %12, align 8, !tbaa !5
  %60 = load ptr, ptr %13, align 8, !tbaa !5
  %61 = call i32 @asn1_bit_octets_to_der_ex(i32 noundef 3, ptr noundef %58, i64 noundef 65, ptr noundef %59, ptr noundef %60)
  %62 = icmp ne i32 %61, 1
  br i1 %62, label %76, label %63

63:                                               ; preds = %57
  %64 = load ptr, ptr %11, align 8, !tbaa !5
  %65 = load ptr, ptr %12, align 8, !tbaa !5
  %66 = load ptr, ptr %13, align 8, !tbaa !5
  %67 = call i32 @asn1_type_to_der(i32 noundef 4, ptr noundef %64, i64 noundef 32, ptr noundef %65, ptr noundef %66)
  %68 = icmp ne i32 %67, 1
  br i1 %68, label %76, label %69

69:                                               ; preds = %63
  %70 = load ptr, ptr %9, align 8, !tbaa !5
  %71 = load i64, ptr %10, align 8, !tbaa !9
  %72 = load ptr, ptr %12, align 8, !tbaa !5
  %73 = load ptr, ptr %13, align 8, !tbaa !5
  %74 = call i32 @asn1_type_to_der(i32 noundef 4, ptr noundef %70, i64 noundef %71, ptr noundef %72, ptr noundef %73)
  %75 = icmp ne i32 %74, 1
  br i1 %75, label %76, label %82

76:                                               ; preds = %69, %63, %57, %51, %45, %40, %36, %32, %28
  br label %77

77:                                               ; preds = %76
  %78 = load ptr, ptr @stderr, align 8, !tbaa !5
  %79 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %78, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 193, ptr noundef @__FUNCTION__.sm9_ciphertext_to_der) #4
  br label %80

80:                                               ; preds = %77
  br label %81

81:                                               ; preds = %80
  store i32 -1, ptr %7, align 4
  store i32 1, ptr %17, align 4
  br label %83

82:                                               ; preds = %69
  store i32 1, ptr %7, align 4
  store i32 1, ptr %17, align 4
  br label %83

83:                                               ; preds = %82, %81, %27
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 65, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  %84 = load i32, ptr %7, align 4
  ret i32 %84
}

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

declare i32 @asn1_bit_octets_to_der_ex(i32 noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef) #2

declare i32 @asn1_type_to_der(i32 noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef) #2

declare i32 @asn1_header_to_der(i32 noundef, i64 noundef, ptr noundef, ptr noundef) #2

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}


; 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 [61 x i8], align 1
@__FUNCTION__.sm9_ciphertext_to_der = external hidden unnamed_addr constant [22 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

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

; 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
define dso_local range(i32 -1, 2) i32 @sm9_ciphertext_to_der(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5) local_unnamed_addr #3 {
  %7 = alloca [65 x i8], align 16
  %8 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 65, ptr nonnull %7) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %8) #4
  store i64 0, ptr %8, align 8, !tbaa !5
  %9 = call i32 @sm9_z256_point_to_uncompressed_octets(ptr noundef %0, ptr noundef nonnull %7) #4
  %.not = icmp eq i32 %9, 1
  br i1 %.not, label %10, label %.sink.split

10:                                               ; preds = %6
  %11 = call i32 @asn1_int_to_der_ex(i32 noundef 2, i32 noundef 0, ptr noundef null, ptr noundef nonnull %8) #4
  %.not19 = icmp eq i32 %11, 1
  br i1 %.not19, label %12, label %.sink.split

12:                                               ; preds = %10
  %13 = call i32 @asn1_bit_octets_to_der_ex(i32 noundef 3, ptr noundef nonnull %7, i64 noundef 65, ptr noundef null, ptr noundef nonnull %8) #4
  %.not20 = icmp eq i32 %13, 1
  br i1 %.not20, label %14, label %.sink.split

14:                                               ; preds = %12
  %15 = call i32 @asn1_type_to_der(i32 noundef 4, ptr noundef %3, i64 noundef 32, ptr noundef null, ptr noundef nonnull %8) #4
  %.not21 = icmp eq i32 %15, 1
  br i1 %.not21, label %16, label %.sink.split

16:                                               ; preds = %14
  %17 = call i32 @asn1_type_to_der(i32 noundef 4, ptr noundef %1, i64 noundef %2, ptr noundef null, ptr noundef nonnull %8) #4
  %.not22 = icmp eq i32 %17, 1
  br i1 %.not22, label %18, label %.sink.split

18:                                               ; preds = %16
  %19 = load i64, ptr %8, align 8, !tbaa !5
  %20 = call i32 @asn1_header_to_der(i32 noundef 48, i64 noundef %19, ptr noundef %4, ptr noundef %5) #4
  %.not23 = icmp eq i32 %20, 1
  br i1 %.not23, label %21, label %.sink.split

21:                                               ; preds = %18
  %22 = call i32 @asn1_int_to_der_ex(i32 noundef 2, i32 noundef 0, ptr noundef %4, ptr noundef %5) #4
  %.not24 = icmp eq i32 %22, 1
  br i1 %.not24, label %23, label %.sink.split

23:                                               ; preds = %21
  %24 = call i32 @asn1_bit_octets_to_der_ex(i32 noundef 3, ptr noundef nonnull %7, i64 noundef 65, ptr noundef %4, ptr noundef %5) #4
  %.not25 = icmp eq i32 %24, 1
  br i1 %.not25, label %25, label %.sink.split

25:                                               ; preds = %23
  %26 = call i32 @asn1_type_to_der(i32 noundef 4, ptr noundef %3, i64 noundef 32, ptr noundef %4, ptr noundef %5) #4
  %.not26 = icmp eq i32 %26, 1
  br i1 %.not26, label %27, label %.sink.split

27:                                               ; preds = %25
  %28 = call i32 @asn1_type_to_der(i32 noundef 4, ptr noundef %1, i64 noundef %2, ptr noundef %4, ptr noundef %5) #4
  %.not27 = icmp eq i32 %28, 1
  br i1 %.not27, label %31, label %.sink.split

.sink.split:                                      ; preds = %27, %25, %23, %21, %18, %16, %14, %12, %10, %6
  %.sink28 = phi i32 [ 181, %6 ], [ 193, %10 ], [ 193, %12 ], [ 193, %14 ], [ 193, %16 ], [ 193, %18 ], [ 193, %21 ], [ 193, %23 ], [ 193, %25 ], [ 193, %27 ]
  %29 = load ptr, ptr @stderr, align 8, !tbaa !9
  %30 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %29, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef %.sink28, ptr noundef nonnull @__FUNCTION__.sm9_ciphertext_to_der) #5
  br label %31

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

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

declare i32 @asn1_bit_octets_to_der_ex(i32 noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare i32 @asn1_type_to_der(i32 noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare i32 @asn1_header_to_der(i32 noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

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 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}


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