; 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_to_der = external hidden unnamed_addr constant [26 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_header_to_der(i32 noundef, i64 noundef, ptr noundef, ptr noundef) #2

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

15:                                               ; preds = %4
  br label %16

16:                                               ; preds = %15
  %17 = load ptr, ptr @stderr, align 8, !tbaa !5
  %18 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %17, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 2415, ptr noundef @__FUNCTION__.x509_ext_key_usage_to_der) #4
  br label %19

19:                                               ; preds = %16
  br label %20

20:                                               ; preds = %19
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %80

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

22:                                               ; preds = %40, %21
  %23 = load i64, ptr %11, align 8, !tbaa !9
  %24 = load i64, ptr %7, align 8, !tbaa !9
  %25 = icmp ult i64 %23, %24
  br i1 %25, label %26, label %43

26:                                               ; preds = %22
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = load i64, ptr %11, align 8, !tbaa !9
  %29 = getelementptr inbounds i32, ptr %27, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !11
  %31 = call i32 @x509_key_purpose_to_der(i32 noundef %30, ptr noundef null, ptr noundef %10)
  %32 = icmp ne i32 %31, 1
  br i1 %32, label %33, label %39

33:                                               ; preds = %26
  br label %34

34:                                               ; preds = %33
  %35 = load ptr, ptr @stderr, align 8, !tbaa !5
  %36 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %35, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 2420, ptr noundef @__FUNCTION__.x509_ext_key_usage_to_der) #4
  br label %37

37:                                               ; preds = %34
  br label %38

38:                                               ; preds = %37
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %80

39:                                               ; preds = %26
  br label %40

40:                                               ; preds = %39
  %41 = load i64, ptr %11, align 8, !tbaa !9
  %42 = add i64 %41, 1
  store i64 %42, ptr %11, align 8, !tbaa !9
  br label %22, !llvm.loop !13

43:                                               ; preds = %22
  %44 = load i64, ptr %10, align 8, !tbaa !9
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  %46 = load ptr, ptr %9, align 8, !tbaa !5
  %47 = call i32 @asn1_header_to_der(i32 noundef 48, i64 noundef %44, ptr noundef %45, ptr noundef %46)
  %48 = icmp ne i32 %47, 1
  br i1 %48, label %49, label %55

49:                                               ; preds = %43
  br label %50

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

53:                                               ; preds = %50
  br label %54

54:                                               ; preds = %53
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %80

55:                                               ; preds = %43
  store i64 0, ptr %11, align 8, !tbaa !9
  br label %56

56:                                               ; preds = %76, %55
  %57 = load i64, ptr %11, align 8, !tbaa !9
  %58 = load i64, ptr %7, align 8, !tbaa !9
  %59 = icmp ult i64 %57, %58
  br i1 %59, label %60, label %79

60:                                               ; preds = %56
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = load i64, ptr %11, align 8, !tbaa !9
  %63 = getelementptr inbounds i32, ptr %61, i64 %62
  %64 = load i32, ptr %63, align 4, !tbaa !11
  %65 = load ptr, ptr %8, align 8, !tbaa !5
  %66 = load ptr, ptr %9, align 8, !tbaa !5
  %67 = call i32 @x509_key_purpose_to_der(i32 noundef %64, ptr noundef %65, ptr noundef %66)
  %68 = icmp ne i32 %67, 1
  br i1 %68, label %69, label %75

69:                                               ; preds = %60
  br label %70

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

73:                                               ; preds = %70
  br label %74

74:                                               ; preds = %73
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %80

75:                                               ; preds = %60
  br label %76

76:                                               ; preds = %75
  %77 = load i64, ptr %11, align 8, !tbaa !9
  %78 = add i64 %77, 1
  store i64 %78, ptr %11, align 8, !tbaa !9
  br label %56, !llvm.loop !15

79:                                               ; preds = %56
  store i32 1, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %80

80:                                               ; preds = %79, %74, %54, %38, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  %81 = load i32, ptr %5, align 4
  ret i32 %81
}

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

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"}
!15 = distinct !{!15, !14}


; 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_to_der = external hidden unnamed_addr constant [26 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_header_to_der(i32 noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

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

.preheader19:                                     ; preds = %4
  %.not23 = icmp eq i64 %1, 0
  br i1 %.not23, label %._crit_edge.thread, label %.lr.ph

7:                                                ; preds = %4
  %8 = load ptr, ptr @stderr, align 8, !tbaa !9
  %9 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %8, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 2415, ptr noundef nonnull @__FUNCTION__.x509_ext_key_usage_to_der) #5
  br label %.loopexit

10:                                               ; preds = %.lr.ph
  %11 = add nuw i64 %.020, 1
  %exitcond.not = icmp eq i64 %11, %1
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !11

.lr.ph:                                           ; preds = %.preheader19, %10
  %.020 = phi i64 [ %11, %10 ], [ 0, %.preheader19 ]
  %12 = getelementptr inbounds i32, ptr %0, i64 %.020
  %13 = load i32, ptr %12, align 4, !tbaa !13
  %14 = call i32 @x509_key_purpose_to_der(i32 noundef %13, ptr noundef null, ptr noundef nonnull %5)
  %.not18 = icmp eq i32 %14, 1
  br i1 %.not18, label %10, label %15

15:                                               ; preds = %.lr.ph
  %16 = load ptr, ptr @stderr, align 8, !tbaa !9
  %17 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %16, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 2420, ptr noundef nonnull @__FUNCTION__.x509_ext_key_usage_to_der) #5
  br label %.loopexit

._crit_edge:                                      ; preds = %10
  %.pre = load i64, ptr %5, align 8, !tbaa !5
  %18 = call i32 @asn1_header_to_der(i32 noundef 48, i64 noundef %.pre, ptr noundef %2, ptr noundef %3) #4
  %.not = icmp eq i32 %18, 1
  br i1 %.not, label %.lr.ph22, label %20

._crit_edge.thread:                               ; preds = %.preheader19
  %19 = tail call i32 @asn1_header_to_der(i32 noundef 48, i64 noundef 0, ptr noundef %2, ptr noundef %3) #4
  %.not26 = icmp eq i32 %19, 1
  br i1 %.not26, label %.loopexit, label %20

20:                                               ; preds = %._crit_edge.thread, %._crit_edge
  %21 = load ptr, ptr @stderr, align 8, !tbaa !9
  %22 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %21, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 2425, ptr noundef nonnull @__FUNCTION__.x509_ext_key_usage_to_der) #5
  br label %.loopexit

23:                                               ; preds = %.lr.ph22
  %24 = add nuw i64 %.121, 1
  %exitcond25.not = icmp eq i64 %24, %1
  br i1 %exitcond25.not, label %.loopexit, label %.lr.ph22, !llvm.loop !15

.lr.ph22:                                         ; preds = %._crit_edge, %23
  %.121 = phi i64 [ %24, %23 ], [ 0, %._crit_edge ]
  %25 = getelementptr inbounds i32, ptr %0, i64 %.121
  %26 = load i32, ptr %25, align 4, !tbaa !13
  %27 = call i32 @x509_key_purpose_to_der(i32 noundef %26, ptr noundef %2, ptr noundef %3)
  %.not17 = icmp eq i32 %27, 1
  br i1 %.not17, label %23, label %28

28:                                               ; preds = %.lr.ph22
  %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 2430, ptr noundef nonnull @__FUNCTION__.x509_ext_key_usage_to_der) #5
  br label %.loopexit

.loopexit:                                        ; preds = %23, %._crit_edge.thread, %28, %20, %15, %7
  %.015 = phi i32 [ -1, %7 ], [ -1, %15 ], [ -1, %20 ], [ -1, %28 ], [ 1, %._crit_edge.thread ], [ 1, %23 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #4
  ret i32 %.015
}

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

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


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