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

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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @x509_key_purpose_from_der(ptr noundef, ptr noundef, ptr noundef) #3

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

21:                                               ; preds = %5
  %22 = load i32, ptr %12, align 4, !tbaa !11
  %23 = icmp slt i32 %22, 0
  br i1 %23, label %24, label %30

24:                                               ; preds = %21
  br label %25

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

28:                                               ; preds = %25
  br label %29

29:                                               ; preds = %28
  br label %30

30:                                               ; preds = %29, %21
  %31 = load i32, ptr %12, align 4, !tbaa !11
  store i32 %31, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %69

32:                                               ; preds = %5
  br label %33

33:                                               ; preds = %53, %32
  %34 = load i64, ptr %14, align 8, !tbaa !9
  %35 = icmp ne i64 %34, 0
  br i1 %35, label %36, label %41

36:                                               ; preds = %33
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = load i64, ptr %37, align 8, !tbaa !9
  %39 = load i64, ptr %9, align 8, !tbaa !9
  %40 = icmp ult i64 %38, %39
  br label %41

41:                                               ; preds = %36, %33
  %42 = phi i1 [ false, %33 ], [ %40, %36 ]
  br i1 %42, label %43, label %59

43:                                               ; preds = %41
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = call i32 @x509_key_purpose_from_der(ptr noundef %44, ptr noundef %13, ptr noundef %14)
  %46 = icmp ne i32 %45, 1
  br i1 %46, label %47, label %53

47:                                               ; preds = %43
  br label %48

48:                                               ; preds = %47
  %49 = load ptr, ptr @stderr, align 8, !tbaa !5
  %50 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %49, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 2450, ptr noundef @__FUNCTION__.x509_ext_key_usage_from_der) #4
  br label %51

51:                                               ; preds = %48
  br label %52

52:                                               ; preds = %51
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %69

53:                                               ; preds = %43
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  %55 = getelementptr inbounds i32, ptr %54, i32 1
  store ptr %55, ptr %7, align 8, !tbaa !5
  %56 = load ptr, ptr %8, align 8, !tbaa !5
  %57 = load i64, ptr %56, align 8, !tbaa !9
  %58 = add i64 %57, 1
  store i64 %58, ptr %56, align 8, !tbaa !9
  br label %33, !llvm.loop !13

59:                                               ; preds = %41
  %60 = load i64, ptr %14, align 8, !tbaa !9
  %61 = icmp ne i64 %60, 0
  br i1 %61, label %62, label %68

62:                                               ; preds = %59
  br label %63

63:                                               ; preds = %62
  %64 = load ptr, ptr @stderr, align 8, !tbaa !5
  %65 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %64, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 2457, ptr noundef @__FUNCTION__.x509_ext_key_usage_from_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 %15, align 4
  br label %69

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

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

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}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @x509_key_purpose_from_der(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

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

.preheader:                                       ; preds = %5
  %9 = load i64, ptr %7, align 8, !tbaa !5
  %.not1215 = icmp eq i64 %9, 0
  br i1 %.not1215, label %.critedge.thread, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.preheader
  %.pre = load i64, ptr %1, align 8, !tbaa !5
  br label %.lr.ph

10:                                               ; preds = %5
  %11 = icmp slt i32 %8, 0
  br i1 %11, label %.critedge.thread.sink.split, label %.critedge.thread

.lr.ph:                                           ; preds = %.lr.ph.preheader, %16
  %12 = phi i64 [ %19, %16 ], [ %.pre, %.lr.ph.preheader ]
  %.01016 = phi ptr [ %17, %16 ], [ %0, %.lr.ph.preheader ]
  %13 = icmp ult i64 %12, %2
  br i1 %13, label %14, label %.critedge.thread.sink.split

14:                                               ; preds = %.lr.ph
  %15 = call i32 @x509_key_purpose_from_der(ptr noundef %.01016, ptr noundef nonnull %6, ptr noundef nonnull %7)
  %.not14 = icmp eq i32 %15, 1
  br i1 %.not14, label %16, label %.critedge.thread.sink.split

16:                                               ; preds = %14
  %17 = getelementptr inbounds i8, ptr %.01016, i64 4
  %18 = load i64, ptr %1, align 8, !tbaa !5
  %19 = add i64 %18, 1
  store i64 %19, ptr %1, align 8, !tbaa !5
  %20 = load i64, ptr %7, align 8, !tbaa !5
  %.not12 = icmp eq i64 %20, 0
  br i1 %.not12, label %.critedge.thread, label %.lr.ph, !llvm.loop !9

.critedge.thread.sink.split:                      ; preds = %.lr.ph, %14, %10
  %.sink17 = phi i32 [ 2445, %10 ], [ 2450, %14 ], [ 2457, %.lr.ph ]
  %.0.ph = phi i32 [ %8, %10 ], [ -1, %14 ], [ -1, %.lr.ph ]
  %21 = load ptr, ptr @stderr, align 8, !tbaa !11
  %22 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %21, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef %.sink17, ptr noundef nonnull @__FUNCTION__.x509_ext_key_usage_from_der) #5
  br label %.critedge.thread

.critedge.thread:                                 ; preds = %16, %.critedge.thread.sink.split, %.preheader, %10
  %.0 = phi i32 [ %8, %10 ], [ 1, %.preheader ], [ %.0.ph, %.critedge.thread.sink.split ], [ 1, %16 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #4
  ret i32 %.0
}

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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass