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

; 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"

%struct.anon = type { i32, i32, i32, i32 }

@stderr = external global ptr, align 8
@.str.3 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [62 x i8], align 1
@x509_name_types_info = external hidden constant [14 x %struct.anon], align 16
@__FUNCTION__.x509_attr_type_and_value_check = external hidden unnamed_addr constant [31 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
declare dso_local i32 @x509_directory_name_check_ex(i32 noundef, ptr noundef, i64 noundef, i64 noundef, i64 noundef) #2

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

12:                                               ; preds = %65, %4
  %13 = load i32, ptr %10, align 4, !tbaa !5
  %14 = icmp slt i32 %13, 14
  br i1 %14, label %15, label %68

15:                                               ; preds = %12
  %16 = load i32, ptr %6, align 4, !tbaa !5
  %17 = load i32, ptr %10, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [14 x %struct.anon], ptr @x509_name_types_info, i64 0, i64 %18
  %20 = getelementptr inbounds %struct.anon, ptr %19, i32 0, i32 0
  %21 = load i32, ptr %20, align 16, !tbaa !13
  %22 = icmp eq i32 %16, %21
  br i1 %22, label %23, label %64

23:                                               ; preds = %15
  %24 = load i32, ptr %10, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [14 x %struct.anon], ptr @x509_name_types_info, i64 0, i64 %25
  %27 = getelementptr inbounds %struct.anon, ptr %26, i32 0, i32 1
  %28 = load i32, ptr %27, align 4, !tbaa !15
  %29 = icmp ne i32 %28, 0
  br i1 %29, label %30, label %39

30:                                               ; preds = %23
  %31 = load i32, ptr %7, align 4, !tbaa !5
  %32 = icmp ne i32 %31, 19
  br i1 %32, label %33, label %39

33:                                               ; preds = %30
  br label %34

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

37:                                               ; preds = %34
  br label %38

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

39:                                               ; preds = %30, %23
  %40 = load i32, ptr %7, align 4, !tbaa !5
  %41 = load ptr, ptr %8, align 8, !tbaa !9
  %42 = load i64, ptr %9, align 8, !tbaa !11
  %43 = load i32, ptr %10, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [14 x %struct.anon], ptr @x509_name_types_info, i64 0, i64 %44
  %46 = getelementptr inbounds %struct.anon, ptr %45, i32 0, i32 2
  %47 = load i32, ptr %46, align 8, !tbaa !16
  %48 = sext i32 %47 to i64
  %49 = load i32, ptr %10, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [14 x %struct.anon], ptr @x509_name_types_info, i64 0, i64 %50
  %52 = getelementptr inbounds %struct.anon, ptr %51, i32 0, i32 3
  %53 = load i32, ptr %52, align 4, !tbaa !17
  %54 = sext i32 %53 to i64
  %55 = call i32 @x509_directory_name_check_ex(i32 noundef %40, ptr noundef %41, i64 noundef %42, i64 noundef %48, i64 noundef %54)
  %56 = icmp ne i32 %55, 1
  br i1 %56, label %57, label %63

57:                                               ; preds = %39
  br label %58

58:                                               ; preds = %57
  %59 = load ptr, ptr @stderr, align 8, !tbaa !9
  %60 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %59, ptr noundef @.str.3, ptr noundef @.str.4, i32 noundef 481, ptr noundef @__FUNCTION__.x509_attr_type_and_value_check) #3
  br label %61

61:                                               ; preds = %58
  br label %62

62:                                               ; preds = %61
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %74

63:                                               ; preds = %39
  store i32 1, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %74

64:                                               ; preds = %15
  br label %65

65:                                               ; preds = %64
  %66 = load i32, ptr %10, align 4, !tbaa !5
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %10, align 4, !tbaa !5
  br label %12, !llvm.loop !18

68:                                               ; preds = %12
  br label %69

69:                                               ; preds = %68
  %70 = load ptr, ptr @stderr, align 8, !tbaa !9
  %71 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %70, ptr noundef @.str.3, ptr noundef @.str.4, i32 noundef 487, ptr noundef @__FUNCTION__.x509_attr_type_and_value_check) #3
  br label %72

72:                                               ; preds = %69
  br label %73

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

74:                                               ; preds = %73, %63, %62, %38
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %75 = load i32, ptr %5, align 4
  ret i32 %75
}

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 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12}
!15 = !{!14, !6, i64 4}
!16 = !{!14, !6, i64 8}
!17 = !{!14, !6, i64 12}
!18 = distinct !{!18, !19}
!19 = !{!"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"

%struct.anon = type { i32, i32, i32, i32 }

@stderr = external local_unnamed_addr global ptr, align 8
@.str.3 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [62 x i8], align 1
@x509_name_types_info = external hidden local_unnamed_addr constant [14 x %struct.anon], align 16
@__FUNCTION__.x509_attr_type_and_value_check = external hidden unnamed_addr constant [31 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: nounwind uwtable
declare dso_local i32 @x509_directory_name_check_ex(i32 noundef, ptr noundef, i64 noundef, i64 noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 2) i32 @x509_attr_type_and_value_check(i32 noundef %0, i32 noundef %1, ptr noundef %2, i64 noundef %3) local_unnamed_addr #1 {
  %5 = load i32, ptr @x509_name_types_info, align 16, !tbaa !5
  %6 = icmp eq i32 %5, %0
  br i1 %6, label %46, label %7

7:                                                ; preds = %4
  %8 = load i32, ptr getelementptr inbounds (i8, ptr @x509_name_types_info, i64 16), align 16, !tbaa !5
  %9 = icmp eq i32 %8, %0
  br i1 %9, label %46, label %10

10:                                               ; preds = %7
  %11 = load i32, ptr getelementptr inbounds (i8, ptr @x509_name_types_info, i64 32), align 16, !tbaa !5
  %12 = icmp eq i32 %11, %0
  br i1 %12, label %46, label %13

13:                                               ; preds = %10
  %14 = load i32, ptr getelementptr inbounds (i8, ptr @x509_name_types_info, i64 48), align 16, !tbaa !5
  %15 = icmp eq i32 %14, %0
  br i1 %15, label %46, label %16

16:                                               ; preds = %13
  %17 = load i32, ptr getelementptr inbounds (i8, ptr @x509_name_types_info, i64 64), align 16, !tbaa !5
  %18 = icmp eq i32 %17, %0
  br i1 %18, label %46, label %19

19:                                               ; preds = %16
  %20 = load i32, ptr getelementptr inbounds (i8, ptr @x509_name_types_info, i64 80), align 16, !tbaa !5
  %21 = icmp eq i32 %20, %0
  br i1 %21, label %46, label %22

22:                                               ; preds = %19
  %23 = load i32, ptr getelementptr inbounds (i8, ptr @x509_name_types_info, i64 96), align 16, !tbaa !5
  %24 = icmp eq i32 %23, %0
  br i1 %24, label %46, label %25

25:                                               ; preds = %22
  %26 = load i32, ptr getelementptr inbounds (i8, ptr @x509_name_types_info, i64 112), align 16, !tbaa !5
  %27 = icmp eq i32 %26, %0
  br i1 %27, label %46, label %28

28:                                               ; preds = %25
  %29 = load i32, ptr getelementptr inbounds (i8, ptr @x509_name_types_info, i64 128), align 16, !tbaa !5
  %30 = icmp eq i32 %29, %0
  br i1 %30, label %46, label %31

31:                                               ; preds = %28
  %32 = load i32, ptr getelementptr inbounds (i8, ptr @x509_name_types_info, i64 144), align 16, !tbaa !5
  %33 = icmp eq i32 %32, %0
  br i1 %33, label %46, label %34

34:                                               ; preds = %31
  %35 = load i32, ptr getelementptr inbounds (i8, ptr @x509_name_types_info, i64 160), align 16, !tbaa !5
  %36 = icmp eq i32 %35, %0
  br i1 %36, label %46, label %37

37:                                               ; preds = %34
  %38 = load i32, ptr getelementptr inbounds (i8, ptr @x509_name_types_info, i64 176), align 16, !tbaa !5
  %39 = icmp eq i32 %38, %0
  br i1 %39, label %46, label %40

40:                                               ; preds = %37
  %41 = load i32, ptr getelementptr inbounds (i8, ptr @x509_name_types_info, i64 192), align 16, !tbaa !5
  %42 = icmp eq i32 %41, %0
  br i1 %42, label %46, label %43

43:                                               ; preds = %40
  %44 = load i32, ptr getelementptr inbounds (i8, ptr @x509_name_types_info, i64 208), align 16, !tbaa !5
  %45 = icmp eq i32 %44, %0
  br i1 %45, label %46, label %.sink.split

46:                                               ; preds = %43, %40, %37, %34, %31, %28, %25, %22, %19, %16, %13, %10, %7, %4
  %.lcssa = phi ptr [ @x509_name_types_info, %4 ], [ getelementptr inbounds (i8, ptr @x509_name_types_info, i64 16), %7 ], [ getelementptr inbounds (i8, ptr @x509_name_types_info, i64 32), %10 ], [ getelementptr inbounds (i8, ptr @x509_name_types_info, i64 48), %13 ], [ getelementptr inbounds (i8, ptr @x509_name_types_info, i64 64), %16 ], [ getelementptr inbounds (i8, ptr @x509_name_types_info, i64 80), %19 ], [ getelementptr inbounds (i8, ptr @x509_name_types_info, i64 96), %22 ], [ getelementptr inbounds (i8, ptr @x509_name_types_info, i64 112), %25 ], [ getelementptr inbounds (i8, ptr @x509_name_types_info, i64 128), %28 ], [ getelementptr inbounds (i8, ptr @x509_name_types_info, i64 144), %31 ], [ getelementptr inbounds (i8, ptr @x509_name_types_info, i64 160), %34 ], [ getelementptr inbounds (i8, ptr @x509_name_types_info, i64 176), %37 ], [ getelementptr inbounds (i8, ptr @x509_name_types_info, i64 192), %40 ], [ getelementptr inbounds (i8, ptr @x509_name_types_info, i64 208), %43 ]
  %47 = getelementptr inbounds i8, ptr %.lcssa, i64 4
  %48 = load i32, ptr %47, align 4, !tbaa !10
  %49 = icmp ne i32 %48, 0
  %50 = icmp ne i32 %1, 19
  %or.cond = and i1 %50, %49
  br i1 %or.cond, label %.sink.split, label %51

51:                                               ; preds = %46
  %52 = getelementptr inbounds i8, ptr %.lcssa, i64 8
  %53 = load i32, ptr %52, align 8, !tbaa !11
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds i8, ptr %.lcssa, i64 12
  %56 = load i32, ptr %55, align 4, !tbaa !12
  %57 = sext i32 %56 to i64
  %58 = tail call i32 @x509_directory_name_check_ex(i32 noundef %1, ptr noundef %2, i64 noundef %3, i64 noundef %54, i64 noundef %57)
  %.not = icmp eq i32 %58, 1
  br i1 %.not, label %61, label %.sink.split

.sink.split:                                      ; preds = %51, %46, %43
  %.sink16 = phi i32 [ 487, %43 ], [ 476, %46 ], [ 481, %51 ]
  %59 = load ptr, ptr @stderr, align 8, !tbaa !13
  %60 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %59, ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.4, i32 noundef %.sink16, ptr noundef nonnull @__FUNCTION__.x509_attr_type_and_value_check) #2
  br label %61

61:                                               ; preds = %.sink.split, %51
  %.012 = phi i32 [ 1, %51 ], [ -1, %.sink.split ]
  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 = { 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, !7, i64 0}
!6 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 4}
!11 = !{!6, !7, i64 8}
!12 = !{!6, !7, i64 12}
!13 = !{!14, !14, i64 0}
!14 = !{!"any pointer", !8, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LoopRotatePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass