; 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_check = external hidden unnamed_addr constant [25 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
define dso_local i32 @x509_ext_key_usage_check(ptr noundef %0, i64 noundef %1, i32 noundef %2) #2 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 -1, ptr %8, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  store i64 0, ptr %9, align 8, !tbaa !9
  br label %11

11:                                               ; preds = %47, %3
  %12 = load i64, ptr %9, align 8, !tbaa !9
  %13 = load i64, ptr %6, align 8, !tbaa !9
  %14 = icmp ult i64 %12, %13
  br i1 %14, label %15, label %50

15:                                               ; preds = %11
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = load i64, ptr %9, align 8, !tbaa !9
  %18 = getelementptr inbounds i32, ptr %16, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !11
  %20 = icmp eq i32 %19, 71
  br i1 %20, label %21, label %22

21:                                               ; preds = %15
  store i32 0, ptr %8, align 4, !tbaa !11
  br label %22

22:                                               ; preds = %21, %15
  %23 = load i32, ptr %7, align 4, !tbaa !11
  switch i32 %23, label %40 [
    i32 0, label %24
    i32 2, label %24
    i32 1, label %32
    i32 3, label %32
  ]

24:                                               ; preds = %22, %22
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = load i64, ptr %9, align 8, !tbaa !9
  %27 = getelementptr inbounds i32, ptr %25, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !11
  %29 = icmp eq i32 %28, 72
  br i1 %29, label %30, label %31

30:                                               ; preds = %24
  store i32 1, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %52

31:                                               ; preds = %24
  br label %46

32:                                               ; preds = %22, %22
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = load i64, ptr %9, align 8, !tbaa !9
  %35 = getelementptr inbounds i32, ptr %33, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !11
  %37 = icmp eq i32 %36, 73
  br i1 %37, label %38, label %39

38:                                               ; preds = %32
  store i32 1, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %52

39:                                               ; preds = %32
  br label %46

40:                                               ; preds = %22
  br label %41

41:                                               ; preds = %40
  %42 = load ptr, ptr @stderr, align 8, !tbaa !5
  %43 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %42, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 2490, ptr noundef @__FUNCTION__.x509_ext_key_usage_check) #3
  br label %44

44:                                               ; preds = %41
  br label %45

45:                                               ; preds = %44
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %52

46:                                               ; preds = %39, %31
  br label %47

47:                                               ; preds = %46
  %48 = load i64, ptr %9, align 8, !tbaa !9
  %49 = add i64 %48, 1
  store i64 %49, ptr %9, align 8, !tbaa !9
  br label %11, !llvm.loop !13

50:                                               ; preds = %11
  %51 = load i32, ptr %8, align 4, !tbaa !11
  store i32 %51, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %52

52:                                               ; preds = %50, %45, %38, %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %53 = load i32, ptr %4, align 4
  ret i32 %53
}

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 = { 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_check = external hidden unnamed_addr constant [25 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #0

; Function Attrs: nofree nounwind uwtable
define dso_local range(i32 -1, 2) i32 @x509_ext_key_usage_check(ptr nocapture noundef readonly %0, i64 noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %.not = icmp eq i64 %1, 0
  br i1 %.not, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %switch = icmp ult i32 %2, 4
  br i1 %switch, label %.lr.ph.split, label %13

.lr.ph.split:                                     ; preds = %.lr.ph
  switch i32 %2, label %.lr.ph.split.split [
    i32 0, label %.lr.ph.split.split.us.preheader
    i32 2, label %.lr.ph.split.split.us.preheader
  ]

.lr.ph.split.split.us.preheader:                  ; preds = %.lr.ph.split, %.lr.ph.split
  br label %.lr.ph.split.split.us

.lr.ph.split.split.us:                            ; preds = %.lr.ph.split.split.us.preheader, %7
  %.014.us = phi i64 [ %9, %7 ], [ 0, %.lr.ph.split.split.us.preheader ]
  %.01113.us = phi i32 [ %spec.select.us, %7 ], [ -1, %.lr.ph.split.split.us.preheader ]
  %4 = getelementptr inbounds i32, ptr %0, i64 %.014.us
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = icmp eq i32 %5, 72
  br i1 %6, label %.loopexit, label %7

7:                                                ; preds = %.lr.ph.split.split.us
  %8 = icmp eq i32 %5, 71
  %spec.select.us = select i1 %8, i32 0, i32 %.01113.us
  %9 = add nuw i64 %.014.us, 1
  %exitcond.not = icmp eq i64 %9, %1
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph.split.split.us, !llvm.loop !9

.lr.ph.split.split:                               ; preds = %.lr.ph.split, %16
  %.014 = phi i64 [ %18, %16 ], [ 0, %.lr.ph.split ]
  %.01113 = phi i32 [ %spec.select, %16 ], [ -1, %.lr.ph.split ]
  %10 = getelementptr inbounds i32, ptr %0, i64 %.014
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = icmp eq i32 %11, 73
  br i1 %12, label %.loopexit, label %16

13:                                               ; preds = %.lr.ph
  %14 = load ptr, ptr @stderr, align 8, !tbaa !11
  %15 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %14, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 2490, ptr noundef nonnull @__FUNCTION__.x509_ext_key_usage_check) #2
  br label %.loopexit

16:                                               ; preds = %.lr.ph.split.split
  %17 = icmp eq i32 %11, 71
  %spec.select = select i1 %17, i32 0, i32 %.01113
  %18 = add nuw i64 %.014, 1
  %exitcond22.not = icmp eq i64 %18, %1
  br i1 %exitcond22.not, label %.loopexit, label %.lr.ph.split.split, !llvm.loop !9

.loopexit:                                        ; preds = %.lr.ph.split.split.us, %7, %.lr.ph.split.split, %16, %3, %13
  %.012 = phi i32 [ -1, %13 ], [ -1, %3 ], [ 1, %.lr.ph.split.split ], [ %spec.select, %16 ], [ 1, %.lr.ph.split.split.us ], [ %spec.select.us, %7 ]
  ret i32 %.012
}

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass