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

@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
@__FUNCTION__.x509_name_set = external hidden unnamed_addr constant [14 x i8], align 1

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @x509_name_add_country_name(ptr noundef, ptr noundef, i64 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @x509_name_add_state_or_province_name(ptr noundef, ptr noundef, i64 noundef, i32 noundef, ptr noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @x509_name_add_locality_name(ptr noundef, ptr noundef, i64 noundef, i32 noundef, ptr noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @x509_name_add_organization_name(ptr noundef, ptr noundef, i64 noundef, i32 noundef, ptr noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @x509_name_add_organizational_unit_name(ptr noundef, ptr noundef, i64 noundef, i32 noundef, ptr noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @x509_name_add_common_name(ptr noundef, ptr noundef, i64 noundef, i32 noundef, ptr noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @x509_name_set(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5, ptr noundef %6, ptr noundef %7, ptr noundef %8) #1 {
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca ptr, align 8
  %18 = alloca ptr, align 8
  %19 = alloca ptr, align 8
  store ptr %0, ptr %11, align 8, !tbaa !5
  store ptr %1, ptr %12, align 8, !tbaa !5
  store i64 %2, ptr %13, align 8, !tbaa !9
  store ptr %3, ptr %14, align 8, !tbaa !5
  store ptr %4, ptr %15, align 8, !tbaa !5
  store ptr %5, ptr %16, align 8, !tbaa !5
  store ptr %6, ptr %17, align 8, !tbaa !5
  store ptr %7, ptr %18, align 8, !tbaa !5
  store ptr %8, ptr %19, align 8, !tbaa !5
  %20 = load ptr, ptr %14, align 8, !tbaa !5
  %21 = icmp ne ptr %20, null
  br i1 %21, label %22, label %31

22:                                               ; preds = %9
  %23 = load ptr, ptr %14, align 8, !tbaa !5
  %24 = call i64 @strlen(ptr noundef %23) #3
  %25 = icmp ne i64 %24, 2
  br i1 %25, label %26, label %31

26:                                               ; preds = %22
  br label %27

27:                                               ; preds = %26
  %28 = load ptr, ptr @stderr, align 8, !tbaa !5
  %29 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %28, ptr noundef @.str.3, ptr noundef @.str.4, i32 noundef 817, ptr noundef @__FUNCTION__.x509_name_set) #4
  br label %30

30:                                               ; preds = %27
  store i32 -1, ptr %10, align 4
  br label %100

31:                                               ; preds = %22, %9
  %32 = load ptr, ptr %12, align 8, !tbaa !5
  store i64 0, ptr %32, align 8, !tbaa !9
  %33 = load ptr, ptr %11, align 8, !tbaa !5
  %34 = load ptr, ptr %12, align 8, !tbaa !5
  %35 = load i64, ptr %13, align 8, !tbaa !9
  %36 = load ptr, ptr %14, align 8, !tbaa !5
  %37 = call i32 @x509_name_add_country_name(ptr noundef %33, ptr noundef %34, i64 noundef %35, ptr noundef %36)
  %38 = icmp slt i32 %37, 0
  br i1 %38, label %94, label %39

39:                                               ; preds = %31
  %40 = load ptr, ptr %11, align 8, !tbaa !5
  %41 = load ptr, ptr %12, align 8, !tbaa !5
  %42 = load i64, ptr %13, align 8, !tbaa !9
  %43 = load ptr, ptr %15, align 8, !tbaa !5
  %44 = call i32 @x509_name_tag(ptr noundef %43)
  %45 = load ptr, ptr %15, align 8, !tbaa !5
  %46 = load ptr, ptr %15, align 8, !tbaa !5
  %47 = call i64 @optstrlen(ptr noundef %46)
  %48 = call i32 @x509_name_add_state_or_province_name(ptr noundef %40, ptr noundef %41, i64 noundef %42, i32 noundef %44, ptr noundef %45, i64 noundef %47)
  %49 = icmp slt i32 %48, 0
  br i1 %49, label %94, label %50

50:                                               ; preds = %39
  %51 = load ptr, ptr %11, align 8, !tbaa !5
  %52 = load ptr, ptr %12, align 8, !tbaa !5
  %53 = load i64, ptr %13, align 8, !tbaa !9
  %54 = load ptr, ptr %16, align 8, !tbaa !5
  %55 = call i32 @x509_name_tag(ptr noundef %54)
  %56 = load ptr, ptr %16, align 8, !tbaa !5
  %57 = load ptr, ptr %16, align 8, !tbaa !5
  %58 = call i64 @optstrlen(ptr noundef %57)
  %59 = call i32 @x509_name_add_locality_name(ptr noundef %51, ptr noundef %52, i64 noundef %53, i32 noundef %55, ptr noundef %56, i64 noundef %58)
  %60 = icmp slt i32 %59, 0
  br i1 %60, label %94, label %61

61:                                               ; preds = %50
  %62 = load ptr, ptr %11, align 8, !tbaa !5
  %63 = load ptr, ptr %12, align 8, !tbaa !5
  %64 = load i64, ptr %13, align 8, !tbaa !9
  %65 = load ptr, ptr %17, align 8, !tbaa !5
  %66 = call i32 @x509_name_tag(ptr noundef %65)
  %67 = load ptr, ptr %17, align 8, !tbaa !5
  %68 = load ptr, ptr %17, align 8, !tbaa !5
  %69 = call i64 @optstrlen(ptr noundef %68)
  %70 = call i32 @x509_name_add_organization_name(ptr noundef %62, ptr noundef %63, i64 noundef %64, i32 noundef %66, ptr noundef %67, i64 noundef %69)
  %71 = icmp slt i32 %70, 0
  br i1 %71, label %94, label %72

72:                                               ; preds = %61
  %73 = load ptr, ptr %11, align 8, !tbaa !5
  %74 = load ptr, ptr %12, align 8, !tbaa !5
  %75 = load i64, ptr %13, align 8, !tbaa !9
  %76 = load ptr, ptr %18, align 8, !tbaa !5
  %77 = call i32 @x509_name_tag(ptr noundef %76)
  %78 = load ptr, ptr %18, align 8, !tbaa !5
  %79 = load ptr, ptr %18, align 8, !tbaa !5
  %80 = call i64 @optstrlen(ptr noundef %79)
  %81 = call i32 @x509_name_add_organizational_unit_name(ptr noundef %73, ptr noundef %74, i64 noundef %75, i32 noundef %77, ptr noundef %78, i64 noundef %80)
  %82 = icmp slt i32 %81, 0
  br i1 %82, label %94, label %83

83:                                               ; preds = %72
  %84 = load ptr, ptr %11, align 8, !tbaa !5
  %85 = load ptr, ptr %12, align 8, !tbaa !5
  %86 = load i64, ptr %13, align 8, !tbaa !9
  %87 = load ptr, ptr %19, align 8, !tbaa !5
  %88 = call i32 @x509_name_tag(ptr noundef %87)
  %89 = load ptr, ptr %19, align 8, !tbaa !5
  %90 = load ptr, ptr %19, align 8, !tbaa !5
  %91 = call i64 @optstrlen(ptr noundef %90)
  %92 = call i32 @x509_name_add_common_name(ptr noundef %84, ptr noundef %85, i64 noundef %86, i32 noundef %88, ptr noundef %89, i64 noundef %91)
  %93 = icmp ne i32 %92, 1
  br i1 %93, label %94, label %99

94:                                               ; preds = %83, %72, %61, %50, %39, %31
  br label %95

95:                                               ; preds = %94
  %96 = load ptr, ptr @stderr, align 8, !tbaa !5
  %97 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %96, ptr noundef @.str.3, ptr noundef @.str.4, i32 noundef 827, ptr noundef @__FUNCTION__.x509_name_set) #4
  br label %98

98:                                               ; preds = %95
  store i32 -1, ptr %10, align 4
  br label %100

99:                                               ; preds = %83
  store i32 1, ptr %10, align 4
  br label %100

100:                                              ; preds = %99, %98, %30
  %101 = load i32, ptr %10, align 4
  ret i32 %101
}

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden i32 @x509_name_tag(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden i64 @optstrlen(ptr noundef) #1

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 willreturn memory(read) "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 willreturn memory(read) }
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}


; 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.3 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [62 x i8], align 1
@__FUNCTION__.x509_name_set = external hidden unnamed_addr constant [14 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_name_add_country_name(ptr noundef, ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @x509_name_add_state_or_province_name(ptr noundef, ptr noundef, i64 noundef, i32 noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @x509_name_add_locality_name(ptr noundef, ptr noundef, i64 noundef, i32 noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @x509_name_add_organization_name(ptr noundef, ptr noundef, i64 noundef, i32 noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @x509_name_add_organizational_unit_name(ptr noundef, ptr noundef, i64 noundef, i32 noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @x509_name_add_common_name(ptr noundef, ptr noundef, i64 noundef, i32 noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 2) i32 @x509_name_set(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5, ptr noundef %6, ptr noundef %7, ptr noundef %8) local_unnamed_addr #1 {
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %12, label %10

10:                                               ; preds = %9
  %11 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %3) #3
  %.not38 = icmp eq i64 %11, 2
  br i1 %.not38, label %12, label %.sink.split

12:                                               ; preds = %10, %9
  store i64 0, ptr %1, align 8, !tbaa !5
  %13 = tail call i32 @x509_name_add_country_name(ptr noundef %0, ptr noundef nonnull %1, i64 noundef %2, ptr noundef %3)
  %14 = icmp slt i32 %13, 0
  br i1 %14, label %.sink.split, label %15

15:                                               ; preds = %12
  %16 = tail call i32 @x509_name_tag(ptr noundef %4)
  %17 = tail call i64 @optstrlen(ptr noundef %4)
  %18 = tail call i32 @x509_name_add_state_or_province_name(ptr noundef %0, ptr noundef nonnull %1, i64 noundef %2, i32 noundef %16, ptr noundef %4, i64 noundef %17)
  %19 = icmp slt i32 %18, 0
  br i1 %19, label %.sink.split, label %20

20:                                               ; preds = %15
  %21 = tail call i32 @x509_name_tag(ptr noundef %5)
  %22 = tail call i64 @optstrlen(ptr noundef %5)
  %23 = tail call i32 @x509_name_add_locality_name(ptr noundef %0, ptr noundef nonnull %1, i64 noundef %2, i32 noundef %21, ptr noundef %5, i64 noundef %22)
  %24 = icmp slt i32 %23, 0
  br i1 %24, label %.sink.split, label %25

25:                                               ; preds = %20
  %26 = tail call i32 @x509_name_tag(ptr noundef %6)
  %27 = tail call i64 @optstrlen(ptr noundef %6)
  %28 = tail call i32 @x509_name_add_organization_name(ptr noundef %0, ptr noundef nonnull %1, i64 noundef %2, i32 noundef %26, ptr noundef %6, i64 noundef %27)
  %29 = icmp slt i32 %28, 0
  br i1 %29, label %.sink.split, label %30

30:                                               ; preds = %25
  %31 = tail call i32 @x509_name_tag(ptr noundef %7)
  %32 = tail call i64 @optstrlen(ptr noundef %7)
  %33 = tail call i32 @x509_name_add_organizational_unit_name(ptr noundef %0, ptr noundef nonnull %1, i64 noundef %2, i32 noundef %31, ptr noundef %7, i64 noundef %32)
  %34 = icmp slt i32 %33, 0
  br i1 %34, label %.sink.split, label %35

35:                                               ; preds = %30
  %36 = tail call i32 @x509_name_tag(ptr noundef %8)
  %37 = tail call i64 @optstrlen(ptr noundef %8)
  %38 = tail call i32 @x509_name_add_common_name(ptr noundef %0, ptr noundef nonnull %1, i64 noundef %2, i32 noundef %36, ptr noundef %8, i64 noundef %37)
  %.not39 = icmp eq i32 %38, 1
  br i1 %.not39, label %41, label %.sink.split

.sink.split:                                      ; preds = %35, %30, %25, %20, %15, %12, %10
  %.sink40 = phi i32 [ 817, %10 ], [ 827, %12 ], [ 827, %15 ], [ 827, %20 ], [ 827, %25 ], [ 827, %30 ], [ 827, %35 ]
  %39 = load ptr, ptr @stderr, align 8, !tbaa !9
  %40 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %39, ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.4, i32 noundef %.sink40, ptr noundef nonnull @__FUNCTION__.x509_name_set) #4
  br label %41

41:                                               ; preds = %.sink.split, %35
  %.0 = phi i32 [ 1, %35 ], [ -1, %.sink.split ]
  ret i32 %.0
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden i32 @x509_name_tag(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden i64 @optstrlen(ptr noundef) local_unnamed_addr #1

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 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 willreturn memory(read) }
attributes #4 = { 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}


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