; 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_enc_algors = external hidden constant [4 x %struct.ASN1_OID_INFO], align 16
@__FUNCTION__.x509_encryption_algor_to_der = external hidden unnamed_addr constant [29 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_encryption_algor_to_der(i32 noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, ptr noundef %4) #3 {
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  %14 = alloca i32, align 4
  store i32 %0, ptr %7, align 4, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !9
  store i64 %2, ptr %9, align 8, !tbaa !11
  store ptr %3, ptr %10, align 8, !tbaa !9
  store ptr %4, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  store i64 0, ptr %13, align 8, !tbaa !11
  %15 = load i32, ptr %7, align 4, !tbaa !5
  %16 = call ptr @asn1_oid_info_from_oid(ptr noundef @x509_enc_algors, i64 noundef 4, i32 noundef %15)
  store ptr %16, ptr %12, align 8, !tbaa !9
  %17 = icmp ne ptr %16, null
  br i1 %17, label %24, label %18

18:                                               ; preds = %5
  br label %19

19:                                               ; preds = %18
  %20 = load ptr, ptr @stderr, align 8, !tbaa !9
  %21 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %20, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 184, ptr noundef @__FUNCTION__.x509_encryption_algor_to_der) #4
  br label %22

22:                                               ; preds = %19
  br label %23

23:                                               ; preds = %22
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %69

24:                                               ; preds = %5
  %25 = load ptr, ptr %12, align 8, !tbaa !9
  %26 = getelementptr inbounds %struct.ASN1_OID_INFO, ptr %25, i32 0, i32 2
  %27 = load ptr, ptr %26, align 8, !tbaa !13
  %28 = load ptr, ptr %12, align 8, !tbaa !9
  %29 = getelementptr inbounds %struct.ASN1_OID_INFO, ptr %28, i32 0, i32 3
  %30 = load i64, ptr %29, align 8, !tbaa !15
  %31 = call i32 @asn1_object_identifier_to_der_ex(i32 noundef 6, ptr noundef %27, i64 noundef %30, ptr noundef null, ptr noundef %13)
  %32 = icmp ne i32 %31, 1
  br i1 %32, label %62, label %33

33:                                               ; preds = %24
  %34 = load ptr, ptr %8, align 8, !tbaa !9
  %35 = load i64, ptr %9, align 8, !tbaa !11
  %36 = call i32 @asn1_type_to_der(i32 noundef 4, ptr noundef %34, i64 noundef %35, ptr noundef null, ptr noundef %13)
  %37 = icmp ne i32 %36, 1
  br i1 %37, label %62, label %38

38:                                               ; preds = %33
  %39 = load i64, ptr %13, align 8, !tbaa !11
  %40 = load ptr, ptr %10, align 8, !tbaa !9
  %41 = load ptr, ptr %11, 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 %62, label %44

44:                                               ; preds = %38
  %45 = load ptr, ptr %12, 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 %12, 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 %10, align 8, !tbaa !9
  %52 = load ptr, ptr %11, 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 %62, label %55

55:                                               ; preds = %44
  %56 = load ptr, ptr %8, align 8, !tbaa !9
  %57 = load i64, ptr %9, align 8, !tbaa !11
  %58 = load ptr, ptr %10, align 8, !tbaa !9
  %59 = load ptr, ptr %11, align 8, !tbaa !9
  %60 = call i32 @asn1_type_to_der(i32 noundef 4, ptr noundef %56, i64 noundef %57, ptr noundef %58, ptr noundef %59)
  %61 = icmp ne i32 %60, 1
  br i1 %61, label %62, label %68

62:                                               ; preds = %55, %44, %38, %33, %24
  br label %63

63:                                               ; preds = %62
  %64 = load ptr, ptr @stderr, align 8, !tbaa !9
  %65 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %64, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 192, ptr noundef @__FUNCTION__.x509_encryption_algor_to_der) #4
  br label %66

66:                                               ; preds = %63
  br label %67

67:                                               ; preds = %66
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %69

68:                                               ; preds = %55
  store i32 1, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %69

69:                                               ; preds = %68, %67, %23
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  %70 = load i32, ptr %6, align 4
  ret i32 %70
}

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

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_enc_algors = external hidden constant [4 x %struct.ASN1_OID_INFO], align 16
@__FUNCTION__.x509_encryption_algor_to_der = external hidden unnamed_addr constant [29 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_encryption_algor_to_der(i32 noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, ptr noundef %4) local_unnamed_addr #3 {
  %6 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #4
  store i64 0, ptr %6, align 8, !tbaa !5
  %7 = tail call ptr @asn1_oid_info_from_oid(ptr noundef nonnull @x509_enc_algors, i64 noundef 4, i32 noundef %0) #4
  %.not = icmp eq ptr %7, null
  br i1 %.not, label %8, label %11

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

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

17:                                               ; preds = %11
  %18 = call i32 @asn1_type_to_der(i32 noundef 4, ptr noundef %1, i64 noundef %2, ptr noundef null, ptr noundef nonnull %6) #4
  %.not17 = icmp eq i32 %18, 1
  br i1 %.not17, label %19, label %28

19:                                               ; preds = %17
  %20 = load i64, ptr %6, align 8, !tbaa !5
  %21 = call i32 @asn1_header_to_der(i32 noundef 48, i64 noundef %20, ptr noundef %3, ptr noundef %4) #4
  %.not18 = icmp eq i32 %21, 1
  br i1 %.not18, label %22, label %28

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

26:                                               ; preds = %22
  %27 = call i32 @asn1_type_to_der(i32 noundef 4, ptr noundef %1, i64 noundef %2, ptr noundef %3, ptr noundef %4) #4
  %.not20 = icmp eq i32 %27, 1
  br i1 %.not20, label %31, label %28

28:                                               ; preds = %11, %17, %19, %22, %26
  %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 192, ptr noundef nonnull @__FUNCTION__.x509_encryption_algor_to_der) #5
  br label %31

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

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

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