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

; 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.ASN1_OID_INFO = type { i32, ptr, ptr, i64, i32, ptr }

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [62 x i8], align 1
@x509_pke_algors = external hidden constant [3 x %struct.ASN1_OID_INFO], align 16
@__FUNCTION__.x509_public_key_encryption_algor_to_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

declare ptr @asn1_oid_info_from_oid(ptr noundef, i64 noundef, i32 noundef) #1

; Function Attrs: nounwind
declare i32 @fprintf(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

declare i32 @asn1_object_identifier_to_der_ex(i32 noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @x509_public_key_encryption_algor_to_der(i32 noundef %0, ptr noundef %1, ptr noundef %2) #3 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  store i64 0, ptr %9, align 8, !tbaa !11
  %11 = load i32, ptr %5, align 4, !tbaa !5
  %12 = icmp ne i32 %11, 8
  br i1 %12, label %13, label %19

13:                                               ; preds = %3
  br label %14

14:                                               ; preds = %13
  %15 = load ptr, ptr @stderr, align 8, !tbaa !9
  %16 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %15, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 493, ptr noundef @__FUNCTION__.x509_public_key_encryption_algor_to_der) #4
  br label %17

17:                                               ; preds = %14
  br label %18

18:                                               ; preds = %17
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %62

19:                                               ; preds = %3
  %20 = load i32, ptr %5, align 4, !tbaa !5
  %21 = call ptr @asn1_oid_info_from_oid(ptr noundef @x509_pke_algors, i64 noundef 3, i32 noundef %20)
  store ptr %21, ptr %8, align 8, !tbaa !9
  %22 = icmp ne ptr %21, null
  br i1 %22, label %29, label %23

23:                                               ; preds = %19
  br label %24

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

27:                                               ; preds = %24
  br label %28

28:                                               ; preds = %27
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %62

29:                                               ; preds = %19
  %30 = load ptr, ptr %8, align 8, !tbaa !9
  %31 = getelementptr inbounds %struct.ASN1_OID_INFO, ptr %30, i32 0, i32 2
  %32 = load ptr, ptr %31, align 8, !tbaa !13
  %33 = load ptr, ptr %8, align 8, !tbaa !9
  %34 = getelementptr inbounds %struct.ASN1_OID_INFO, ptr %33, i32 0, i32 3
  %35 = load i64, ptr %34, align 8, !tbaa !15
  %36 = call i32 @asn1_object_identifier_to_der_ex(i32 noundef 6, ptr noundef %32, i64 noundef %35, ptr noundef null, ptr noundef %9)
  %37 = icmp ne i32 %36, 1
  br i1 %37, label %55, label %38

38:                                               ; preds = %29
  %39 = load i64, ptr %9, align 8, !tbaa !11
  %40 = load ptr, ptr %6, align 8, !tbaa !9
  %41 = load ptr, ptr %7, align 8, !tbaa !9
  %42 = call i32 @asn1_header_to_der(i32 noundef 48, i64 noundef %39, ptr noundef %40, ptr noundef %41)
  %43 = icmp ne i32 %42, 1
  br i1 %43, label %55, label %44

44:                                               ; preds = %38
  %45 = load ptr, ptr %8, align 8, !tbaa !9
  %46 = getelementptr inbounds %struct.ASN1_OID_INFO, ptr %45, i32 0, i32 2
  %47 = load ptr, ptr %46, align 8, !tbaa !13
  %48 = load ptr, ptr %8, align 8, !tbaa !9
  %49 = getelementptr inbounds %struct.ASN1_OID_INFO, ptr %48, i32 0, i32 3
  %50 = load i64, ptr %49, align 8, !tbaa !15
  %51 = load ptr, ptr %6, align 8, !tbaa !9
  %52 = load ptr, ptr %7, align 8, !tbaa !9
  %53 = call i32 @asn1_object_identifier_to_der_ex(i32 noundef 6, ptr noundef %47, i64 noundef %50, ptr noundef %51, ptr noundef %52)
  %54 = icmp ne i32 %53, 1
  br i1 %54, label %55, label %61

55:                                               ; preds = %44, %38, %29
  br label %56

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

59:                                               ; preds = %56
  br label %60

60:                                               ; preds = %59
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %62

61:                                               ; preds = %44
  store i32 1, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %62

62:                                               ; preds = %61, %60, %28, %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  %63 = load i32, ptr %4, align 4
  ret i32 %63
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 "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 = !{!"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}
!13 = !{!14, !10, i64 16}
!14 = !{!"", !6, i64 0, !10, i64 8, !10, i64 16, !12, i64 24, !6, i64 32, !10, i64 40}
!15 = !{!14, !12, i64 24}


; 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.ASN1_OID_INFO = type { i32, ptr, ptr, i64, i32, ptr }

@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 [62 x i8], align 1
@x509_pke_algors = external hidden constant [3 x %struct.ASN1_OID_INFO], align 16
@__FUNCTION__.x509_public_key_encryption_algor_to_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

declare ptr @asn1_oid_info_from_oid(ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) 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

declare i32 @asn1_object_identifier_to_der_ex(i32 noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 2) i32 @x509_public_key_encryption_algor_to_der(i32 noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #3 {
  %4 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #4
  store i64 0, ptr %4, align 8, !tbaa !5
  %.not = icmp eq i32 %0, 8
  br i1 %.not, label %8, label %5

5:                                                ; preds = %3
  %6 = load ptr, ptr @stderr, align 8, !tbaa !9
  %7 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %6, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 493, ptr noundef nonnull @__FUNCTION__.x509_public_key_encryption_algor_to_der) #5
  br label %29

8:                                                ; preds = %3
  %9 = tail call ptr @asn1_oid_info_from_oid(ptr noundef nonnull @x509_pke_algors, i64 noundef 3, i32 noundef 8) #4
  %.not12 = icmp eq ptr %9, null
  br i1 %.not12, label %10, label %13

10:                                               ; preds = %8
  %11 = load ptr, ptr @stderr, align 8, !tbaa !9
  %12 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %11, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 497, ptr noundef nonnull @__FUNCTION__.x509_public_key_encryption_algor_to_der) #5
  br label %29

13:                                               ; preds = %8
  %14 = getelementptr inbounds i8, ptr %9, i64 16
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  %16 = getelementptr inbounds i8, ptr %9, i64 24
  %17 = load i64, ptr %16, align 8, !tbaa !14
  %18 = call i32 @asn1_object_identifier_to_der_ex(i32 noundef 6, ptr noundef %15, i64 noundef %17, ptr noundef null, ptr noundef nonnull %4) #4
  %.not13 = icmp eq i32 %18, 1
  br i1 %.not13, label %19, label %26

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

22:                                               ; preds = %19
  %23 = load ptr, ptr %14, align 8, !tbaa !11
  %24 = load i64, ptr %16, align 8, !tbaa !14
  %25 = call i32 @asn1_object_identifier_to_der_ex(i32 noundef 6, ptr noundef %23, i64 noundef %24, ptr noundef %1, ptr noundef %2) #4
  %.not15 = icmp eq i32 %25, 1
  br i1 %.not15, label %29, label %26

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

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { 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 #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}
!11 = !{!12, !10, i64 16}
!12 = !{!"", !13, i64 0, !10, i64 8, !10, i64 16, !6, i64 24, !13, i64 32, !10, i64 40}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !6, i64 24}


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