; 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
@x509_revoke_reason_flags_count = external hidden global i64, align 8
@__FUNCTION__.x509_revoke_reason_flag_name = external hidden unnamed_addr constant [29 x i8], align 1
@x509_revoke_reason_flags = external hidden global [9 x ptr], align 16

; 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 ptr @x509_revoke_reason_flag_name(i32 noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  store i64 0, ptr %4, align 8, !tbaa !9
  br label %6

6:                                                ; preds = %31, %1
  %7 = load i64, ptr %4, align 8, !tbaa !9
  %8 = load i64, ptr @x509_revoke_reason_flags_count, align 8, !tbaa !9
  %9 = icmp ult i64 %7, %8
  br i1 %9, label %10, label %34

10:                                               ; preds = %6
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = and i32 %11, 1
  %13 = icmp ne i32 %12, 0
  br i1 %13, label %14, label %28

14:                                               ; preds = %10
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = ashr i32 %15, 1
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %18, label %24

18:                                               ; preds = %14
  br label %19

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

22:                                               ; preds = %19
  br label %23

23:                                               ; preds = %22
  store ptr null, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %35

24:                                               ; preds = %14
  %25 = load i64, ptr %4, align 8, !tbaa !9
  %26 = getelementptr inbounds [9 x ptr], ptr @x509_revoke_reason_flags, i64 0, i64 %25
  %27 = load ptr, ptr %26, align 8, !tbaa !11
  store ptr %27, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %35

28:                                               ; preds = %10
  %29 = load i32, ptr %3, align 4, !tbaa !5
  %30 = ashr i32 %29, 1
  store i32 %30, ptr %3, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %28
  %32 = load i64, ptr %4, align 8, !tbaa !9
  %33 = add i64 %32, 1
  store i64 %33, ptr %4, align 8, !tbaa !9
  br label %6, !llvm.loop !13

34:                                               ; preds = %6
  store ptr null, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %35

35:                                               ; preds = %34, %24, %23
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %36 = load ptr, ptr %2, align 8
  ret ptr %36
}

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 = !{!"int", !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 = !{!"any pointer", !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
@x509_revoke_reason_flags_count = external hidden local_unnamed_addr global i64, align 8
@__FUNCTION__.x509_revoke_reason_flag_name = external hidden unnamed_addr constant [29 x i8], align 1
@x509_revoke_reason_flags = external hidden local_unnamed_addr global [9 x ptr], align 16

; 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 ptr @x509_revoke_reason_flag_name(i32 noundef %0) local_unnamed_addr #1 {
  %2 = load i64, ptr @x509_revoke_reason_flags_count, align 8, !tbaa !5
  %.not13 = icmp eq i64 %2, 0
  br i1 %.not13, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %1, %11
  %.012 = phi i64 [ %13, %11 ], [ 0, %1 ]
  %.0611 = phi i32 [ %12, %11 ], [ %0, %1 ]
  %3 = and i32 %.0611, 1
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %11, label %4

4:                                                ; preds = %.lr.ph
  %.not8 = icmp ult i32 %.0611, 2
  br i1 %.not8, label %8, label %5

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

8:                                                ; preds = %4
  %9 = getelementptr inbounds [9 x ptr], ptr @x509_revoke_reason_flags, i64 0, i64 %.012
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  br label %.loopexit

11:                                               ; preds = %.lr.ph
  %12 = ashr exact i32 %.0611, 1
  %13 = add nuw i64 %.012, 1
  %exitcond.not = icmp eq i64 %13, %2
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !11

.loopexit:                                        ; preds = %11, %1, %8, %5
  %.07 = phi ptr [ null, %5 ], [ %10, %8 ], [ null, %1 ], [ null, %11 ]
  ret ptr %.07
}

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 = !{!"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"}


; Effective O3 passes: CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass