; 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_key_usage_check = external hidden unnamed_addr constant [21 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @x509_key_usage_check(i32 noundef %0, i32 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  %6 = load i32, ptr %4, align 4, !tbaa !5
  %7 = icmp eq i32 %6, -1
  br i1 %7, label %8, label %9

8:                                                ; preds = %2
  store i32 0, ptr %3, align 4
  br label %91

9:                                                ; preds = %2
  %10 = load i32, ptr %4, align 4, !tbaa !5
  %11 = icmp ne i32 %10, 0
  br i1 %11, label %17, label %12

12:                                               ; preds = %9
  br label %13

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

16:                                               ; preds = %13
  store i32 -1, ptr %3, align 4
  br label %91

17:                                               ; preds = %9
  %18 = load i32, ptr %5, align 4, !tbaa !5
  switch i32 %18, label %85 [
    i32 -1, label %90
    i32 0, label %19
    i32 1, label %19
    i32 2, label %42
    i32 3, label %42
    i32 4, label %65
    i32 6, label %75
  ]

19:                                               ; preds = %17, %17
  %20 = load i32, ptr %4, align 4, !tbaa !5
  %21 = and i32 %20, 1
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %28, 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 1264, ptr noundef @__FUNCTION__.x509_key_usage_check) #2
  br label %27

27:                                               ; preds = %24
  store i32 -1, ptr %3, align 4
  br label %91

28:                                               ; preds = %19
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = and i32 %29, 32
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %36, label %32

32:                                               ; preds = %28
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = and i32 %33, 64
  %35 = icmp ne i32 %34, 0
  br i1 %35, label %36, label %41

36:                                               ; preds = %32, %28
  br label %37

37:                                               ; preds = %36
  %38 = load ptr, ptr @stderr, align 8, !tbaa !9
  %39 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %38, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 1269, ptr noundef @__FUNCTION__.x509_key_usage_check) #2
  br label %40

40:                                               ; preds = %37
  store i32 -1, ptr %3, align 4
  br label %91

41:                                               ; preds = %32
  br label %90

42:                                               ; preds = %17, %17
  %43 = load i32, ptr %4, align 4, !tbaa !5
  %44 = and i32 %43, 4
  %45 = icmp ne i32 %44, 0
  br i1 %45, label %51, label %46

46:                                               ; preds = %42
  br label %47

47:                                               ; preds = %46
  %48 = load ptr, ptr @stderr, align 8, !tbaa !9
  %49 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %48, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 1277, ptr noundef @__FUNCTION__.x509_key_usage_check) #2
  br label %50

50:                                               ; preds = %47
  store i32 -1, ptr %3, align 4
  br label %91

51:                                               ; preds = %42
  %52 = load i32, ptr %4, align 4, !tbaa !5
  %53 = and i32 %52, 32
  %54 = icmp ne i32 %53, 0
  br i1 %54, label %59, label %55

55:                                               ; preds = %51
  %56 = load i32, ptr %4, align 4, !tbaa !5
  %57 = and i32 %56, 64
  %58 = icmp ne i32 %57, 0
  br i1 %58, label %59, label %64

59:                                               ; preds = %55, %51
  br label %60

60:                                               ; preds = %59
  %61 = load ptr, ptr @stderr, align 8, !tbaa !9
  %62 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %61, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 1282, ptr noundef @__FUNCTION__.x509_key_usage_check) #2
  br label %63

63:                                               ; preds = %60
  store i32 -1, ptr %3, align 4
  br label %91

64:                                               ; preds = %55
  br label %90

65:                                               ; preds = %17
  %66 = load i32, ptr %4, align 4, !tbaa !5
  %67 = and i32 %66, 32
  %68 = icmp ne i32 %67, 0
  br i1 %68, label %74, label %69

69:                                               ; preds = %65
  br label %70

70:                                               ; preds = %69
  %71 = load ptr, ptr @stderr, align 8, !tbaa !9
  %72 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %71, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 1289, ptr noundef @__FUNCTION__.x509_key_usage_check) #2
  br label %73

73:                                               ; preds = %70
  store i32 -1, ptr %3, align 4
  br label %91

74:                                               ; preds = %65
  br label %90

75:                                               ; preds = %17
  %76 = load i32, ptr %4, align 4, !tbaa !5
  %77 = and i32 %76, 64
  %78 = icmp ne i32 %77, 0
  br i1 %78, label %84, label %79

79:                                               ; preds = %75
  br label %80

80:                                               ; preds = %79
  %81 = load ptr, ptr @stderr, align 8, !tbaa !9
  %82 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %81, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 1296, ptr noundef @__FUNCTION__.x509_key_usage_check) #2
  br label %83

83:                                               ; preds = %80
  store i32 -1, ptr %3, align 4
  br label %91

84:                                               ; preds = %75
  br label %90

85:                                               ; preds = %17
  br label %86

86:                                               ; preds = %85
  %87 = load ptr, ptr @stderr, align 8, !tbaa !9
  %88 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %87, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 1302, ptr noundef @__FUNCTION__.x509_key_usage_check) #2
  br label %89

89:                                               ; preds = %86
  store i32 -1, ptr %3, align 4
  br label %91

90:                                               ; preds = %84, %74, %64, %41, %17
  store i32 1, ptr %3, align 4
  br label %91

91:                                               ; preds = %90, %89, %83, %73, %63, %50, %40, %27, %16, %8
  %92 = load i32, ptr %3, align 4
  ret i32 %92
}

attributes #0 = { 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 = { 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 = { 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}


; 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_key_usage_check = external hidden unnamed_addr constant [21 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_key_usage_check(i32 noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  switch i32 %0, label %3 [
    i32 -1, label %18
    i32 0, label %.sink.split
  ]

3:                                                ; preds = %2
  switch i32 %1, label %.sink.split [
    i32 -1, label %18
    i32 0, label %4
    i32 1, label %4
    i32 2, label %8
    i32 3, label %8
    i32 4, label %12
    i32 6, label %14
  ]

4:                                                ; preds = %3, %3
  %5 = and i32 %0, 1
  %.not18 = icmp eq i32 %5, 0
  br i1 %.not18, label %.sink.split, label %6

6:                                                ; preds = %4
  %7 = and i32 %0, 96
  %or.cond = icmp eq i32 %7, 0
  br i1 %or.cond, label %18, label %.sink.split

8:                                                ; preds = %3, %3
  %9 = and i32 %0, 4
  %.not15 = icmp eq i32 %9, 0
  br i1 %.not15, label %.sink.split, label %10

10:                                               ; preds = %8
  %11 = and i32 %0, 96
  %or.cond21 = icmp eq i32 %11, 0
  br i1 %or.cond21, label %18, label %.sink.split

12:                                               ; preds = %3
  %13 = and i32 %0, 32
  %.not14 = icmp eq i32 %13, 0
  br i1 %.not14, label %.sink.split, label %18

14:                                               ; preds = %3
  %15 = and i32 %0, 64
  %.not13 = icmp eq i32 %15, 0
  br i1 %.not13, label %.sink.split, label %18

.sink.split:                                      ; preds = %3, %14, %12, %10, %8, %6, %4, %2
  %.sink22 = phi i32 [ 1254, %2 ], [ 1264, %4 ], [ 1269, %6 ], [ 1277, %8 ], [ 1282, %10 ], [ 1289, %12 ], [ 1296, %14 ], [ 1302, %3 ]
  %16 = load ptr, ptr @stderr, align 8, !tbaa !5
  %17 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %16, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef %.sink22, ptr noundef nonnull @__FUNCTION__.x509_key_usage_check) #2
  br label %18

18:                                               ; preds = %.sink.split, %3, %12, %14, %6, %10, %2
  %.0 = phi i32 [ 0, %2 ], [ 1, %10 ], [ 1, %6 ], [ 1, %14 ], [ 1, %12 ], [ 1, %3 ], [ -1, %.sink.split ]
  ret i32 %.0
}

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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


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