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

; 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 [58 x i8], align 1
@__FUNCTION__.asn1_integer_from_der_ex = external hidden unnamed_addr constant [25 x i8], align 1

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

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

16:                                               ; preds = %5
  %17 = load ptr, ptr %9, align 8, !tbaa !9
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %29

19:                                               ; preds = %16
  %20 = load ptr, ptr %10, align 8, !tbaa !9
  %21 = icmp ne ptr %20, null
  br i1 %21, label %22, label %29

22:                                               ; preds = %19
  %23 = load ptr, ptr %10, align 8, !tbaa !9
  %24 = load ptr, ptr %23, align 8, !tbaa !9
  %25 = icmp ne ptr %24, null
  br i1 %25, label %26, label %29

26:                                               ; preds = %22
  %27 = load ptr, ptr %11, align 8, !tbaa !9
  %28 = icmp ne ptr %27, null
  br i1 %28, label %35, label %29

29:                                               ; preds = %26, %22, %19, %16, %5
  br label %30

30:                                               ; preds = %29
  %31 = load ptr, ptr @stderr, align 8, !tbaa !9
  %32 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %31, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 574, ptr noundef @__FUNCTION__.asn1_integer_from_der_ex) #3
  br label %33

33:                                               ; preds = %30
  br label %34

34:                                               ; preds = %33
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %148

35:                                               ; preds = %26
  %36 = load ptr, ptr %11, align 8, !tbaa !9
  %37 = load i64, ptr %36, align 8, !tbaa !11
  %38 = icmp eq i64 %37, 0
  br i1 %38, label %46, label %39

39:                                               ; preds = %35
  %40 = load ptr, ptr %10, align 8, !tbaa !9
  %41 = load ptr, ptr %40, align 8, !tbaa !9
  %42 = load i8, ptr %41, align 1, !tbaa !13
  %43 = zext i8 %42 to i32
  %44 = load i32, ptr %7, align 4, !tbaa !5
  %45 = icmp ne i32 %43, %44
  br i1 %45, label %46, label %49

46:                                               ; preds = %39, %35
  %47 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr null, ptr %47, align 8, !tbaa !9
  %48 = load ptr, ptr %9, align 8, !tbaa !9
  store i64 0, ptr %48, align 8, !tbaa !11
  store i32 0, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %148

49:                                               ; preds = %39
  %50 = load ptr, ptr %10, align 8, !tbaa !9
  %51 = load ptr, ptr %50, align 8, !tbaa !9
  %52 = getelementptr inbounds i8, ptr %51, i32 1
  store ptr %52, ptr %50, align 8, !tbaa !9
  %53 = load ptr, ptr %11, align 8, !tbaa !9
  %54 = load i64, ptr %53, align 8, !tbaa !11
  %55 = add i64 %54, -1
  store i64 %55, ptr %53, align 8, !tbaa !11
  %56 = load ptr, ptr %10, align 8, !tbaa !9
  %57 = load ptr, ptr %11, align 8, !tbaa !9
  %58 = call i32 @asn1_length_from_der(ptr noundef %12, ptr noundef %56, ptr noundef %57)
  %59 = icmp ne i32 %58, 1
  br i1 %59, label %60, label %66

60:                                               ; preds = %49
  br label %61

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

64:                                               ; preds = %61
  br label %65

65:                                               ; preds = %64
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %148

66:                                               ; preds = %49
  %67 = load i64, ptr %12, align 8, !tbaa !11
  %68 = icmp eq i64 %67, 0
  br i1 %68, label %69, label %75

69:                                               ; preds = %66
  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 593, ptr noundef @__FUNCTION__.asn1_integer_from_der_ex) #3
  br label %73

73:                                               ; preds = %70
  br label %74

74:                                               ; preds = %73
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %148

75:                                               ; preds = %66
  %76 = load ptr, ptr %10, align 8, !tbaa !9
  %77 = load ptr, ptr %76, align 8, !tbaa !9
  %78 = load i8, ptr %77, align 1, !tbaa !13
  %79 = zext i8 %78 to i32
  %80 = and i32 %79, 128
  %81 = icmp ne i32 %80, 0
  br i1 %81, label %82, label %88

82:                                               ; preds = %75
  br label %83

83:                                               ; preds = %82
  %84 = load ptr, ptr @stderr, align 8, !tbaa !9
  %85 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %84, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 599, ptr noundef @__FUNCTION__.asn1_integer_from_der_ex) #3
  br label %86

86:                                               ; preds = %83
  br label %87

87:                                               ; preds = %86
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %148

88:                                               ; preds = %75
  %89 = load ptr, ptr %10, align 8, !tbaa !9
  %90 = load ptr, ptr %89, align 8, !tbaa !9
  %91 = load i8, ptr %90, align 1, !tbaa !13
  %92 = zext i8 %91 to i32
  %93 = icmp eq i32 %92, 0
  br i1 %93, label %94, label %119

94:                                               ; preds = %88
  %95 = load i64, ptr %12, align 8, !tbaa !11
  %96 = icmp ugt i64 %95, 1
  br i1 %96, label %97, label %119

97:                                               ; preds = %94
  %98 = load ptr, ptr %10, align 8, !tbaa !9
  %99 = load ptr, ptr %98, align 8, !tbaa !9
  %100 = getelementptr inbounds i8, ptr %99, i32 1
  store ptr %100, ptr %98, align 8, !tbaa !9
  %101 = load ptr, ptr %11, align 8, !tbaa !9
  %102 = load i64, ptr %101, align 8, !tbaa !11
  %103 = add i64 %102, -1
  store i64 %103, ptr %101, align 8, !tbaa !11
  %104 = load i64, ptr %12, align 8, !tbaa !11
  %105 = add i64 %104, -1
  store i64 %105, ptr %12, align 8, !tbaa !11
  %106 = load ptr, ptr %10, align 8, !tbaa !9
  %107 = load ptr, ptr %106, align 8, !tbaa !9
  %108 = load i8, ptr %107, align 1, !tbaa !13
  %109 = zext i8 %108 to i32
  %110 = and i32 %109, 128
  %111 = icmp eq i32 %110, 0
  br i1 %111, label %112, label %118

112:                                              ; preds = %97
  br label %113

113:                                              ; preds = %112
  %114 = load ptr, ptr @stderr, align 8, !tbaa !9
  %115 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %114, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 611, ptr noundef @__FUNCTION__.asn1_integer_from_der_ex) #3
  br label %116

116:                                              ; preds = %113
  br label %117

117:                                              ; preds = %116
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %148

118:                                              ; preds = %97
  br label %119

119:                                              ; preds = %118, %94, %88
  %120 = load ptr, ptr %10, align 8, !tbaa !9
  %121 = load ptr, ptr %120, align 8, !tbaa !9
  %122 = load i8, ptr %121, align 1, !tbaa !13
  %123 = zext i8 %122 to i32
  %124 = icmp eq i32 %123, 0
  br i1 %124, label %125, label %134

125:                                              ; preds = %119
  %126 = load i64, ptr %12, align 8, !tbaa !11
  %127 = icmp ugt i64 %126, 1
  br i1 %127, label %128, label %134

128:                                              ; preds = %125
  br label %129

129:                                              ; preds = %128
  %130 = load ptr, ptr @stderr, align 8, !tbaa !9
  %131 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %130, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 618, ptr noundef @__FUNCTION__.asn1_integer_from_der_ex) #3
  br label %132

132:                                              ; preds = %129
  br label %133

133:                                              ; preds = %132
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %148

134:                                              ; preds = %125, %119
  %135 = load ptr, ptr %10, align 8, !tbaa !9
  %136 = load ptr, ptr %135, align 8, !tbaa !9
  %137 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %136, ptr %137, align 8, !tbaa !9
  %138 = load i64, ptr %12, align 8, !tbaa !11
  %139 = load ptr, ptr %9, align 8, !tbaa !9
  store i64 %138, ptr %139, align 8, !tbaa !11
  %140 = load i64, ptr %12, align 8, !tbaa !11
  %141 = load ptr, ptr %10, align 8, !tbaa !9
  %142 = load ptr, ptr %141, align 8, !tbaa !9
  %143 = getelementptr inbounds i8, ptr %142, i64 %140
  store ptr %143, ptr %141, align 8, !tbaa !9
  %144 = load i64, ptr %12, align 8, !tbaa !11
  %145 = load ptr, ptr %11, align 8, !tbaa !9
  %146 = load i64, ptr %145, align 8, !tbaa !11
  %147 = sub i64 %146, %144
  store i64 %147, ptr %145, align 8, !tbaa !11
  store i32 1, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %148

148:                                              ; preds = %134, %133, %117, %87, %74, %65, %46, %34
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  %149 = load i32, ptr %6, align 4
  ret i32 %149
}

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!7, !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 [58 x i8], align 1
@__FUNCTION__.asn1_integer_from_der_ex = external hidden unnamed_addr constant [25 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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 2) i32 @asn1_integer_from_der_ex(i32 noundef %0, ptr noundef writeonly %1, ptr noundef writeonly %2, ptr noundef %3, ptr noundef %4) local_unnamed_addr #2 {
  %6 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #3
  %7 = icmp ne ptr %1, null
  %8 = icmp ne ptr %2, null
  %or.cond = and i1 %7, %8
  %9 = icmp ne ptr %3, null
  %or.cond3 = and i1 %or.cond, %9
  br i1 %or.cond3, label %10, label %14

10:                                               ; preds = %5
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = icmp ne ptr %11, null
  %13 = icmp ne ptr %4, null
  %or.cond5 = and i1 %13, %12
  br i1 %or.cond5, label %17, label %14

14:                                               ; preds = %5, %10
  %15 = load ptr, ptr @stderr, align 8, !tbaa !5
  %16 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %15, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 574, ptr noundef nonnull @__FUNCTION__.asn1_integer_from_der_ex) #4
  br label %68

17:                                               ; preds = %10
  %18 = load i64, ptr %4, align 8, !tbaa !9
  %19 = icmp eq i64 %18, 0
  br i1 %19, label %23, label %20

20:                                               ; preds = %17
  %21 = load i8, ptr %11, align 1, !tbaa !11
  %22 = zext i8 %21 to i32
  %.not = icmp eq i32 %22, %0
  br i1 %.not, label %24, label %23

23:                                               ; preds = %20, %17
  store ptr null, ptr %1, align 8, !tbaa !5
  store i64 0, ptr %2, align 8, !tbaa !9
  br label %68

24:                                               ; preds = %20
  %25 = getelementptr inbounds i8, ptr %11, i64 1
  store ptr %25, ptr %3, align 8, !tbaa !5
  %26 = add i64 %18, -1
  store i64 %26, ptr %4, align 8, !tbaa !9
  %27 = call i32 @asn1_length_from_der(ptr noundef nonnull %6, ptr noundef nonnull %3, ptr noundef nonnull %4)
  %.not40 = icmp eq i32 %27, 1
  br i1 %.not40, label %31, label %28

28:                                               ; preds = %24
  %29 = load ptr, ptr @stderr, align 8, !tbaa !5
  %30 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %29, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 589, ptr noundef nonnull @__FUNCTION__.asn1_integer_from_der_ex) #4
  br label %68

31:                                               ; preds = %24
  %32 = load i64, ptr %6, align 8
  %33 = icmp eq i64 %32, 0
  br i1 %33, label %34, label %37

34:                                               ; preds = %31
  %35 = load ptr, ptr @stderr, align 8, !tbaa !5
  %36 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %35, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 593, ptr noundef nonnull @__FUNCTION__.asn1_integer_from_der_ex) #4
  br label %68

37:                                               ; preds = %31
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = load i8, ptr %38, align 1, !tbaa !11
  %.not41 = icmp sgt i8 %39, -1
  br i1 %.not41, label %43, label %40

40:                                               ; preds = %37
  %41 = load ptr, ptr @stderr, align 8, !tbaa !5
  %42 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %41, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 599, ptr noundef nonnull @__FUNCTION__.asn1_integer_from_der_ex) #4
  br label %68

43:                                               ; preds = %37
  %44 = icmp eq i8 %39, 0
  %45 = icmp ne i64 %32, 1
  %or.cond7 = and i1 %45, %44
  br i1 %or.cond7, label %46, label %56

46:                                               ; preds = %43
  %47 = getelementptr inbounds i8, ptr %38, i64 1
  store ptr %47, ptr %3, align 8, !tbaa !5
  %48 = load i64, ptr %4, align 8, !tbaa !9
  %49 = add i64 %48, -1
  store i64 %49, ptr %4, align 8, !tbaa !9
  %50 = add i64 %32, -1
  store i64 %50, ptr %6, align 8, !tbaa !9
  %51 = load i8, ptr %47, align 1, !tbaa !11
  %52 = icmp sgt i8 %51, -1
  br i1 %52, label %53, label %.thread

53:                                               ; preds = %46
  %54 = load ptr, ptr @stderr, align 8, !tbaa !5
  %55 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %54, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 611, ptr noundef nonnull @__FUNCTION__.asn1_integer_from_der_ex) #4
  br label %68

56:                                               ; preds = %43
  %57 = icmp eq i8 %39, 0
  %58 = icmp ne i64 %32, 1
  %or.cond9 = and i1 %57, %58
  br i1 %or.cond9, label %59, label %.thread

59:                                               ; preds = %56
  %60 = load ptr, ptr @stderr, align 8, !tbaa !5
  %61 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %60, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 618, ptr noundef nonnull @__FUNCTION__.asn1_integer_from_der_ex) #4
  br label %68

.thread:                                          ; preds = %46, %56
  %62 = phi ptr [ %38, %56 ], [ %47, %46 ]
  %63 = phi i64 [ %32, %56 ], [ %50, %46 ]
  store ptr %62, ptr %1, align 8, !tbaa !5
  store i64 %63, ptr %2, align 8, !tbaa !9
  %64 = load ptr, ptr %3, align 8, !tbaa !5
  %65 = getelementptr inbounds i8, ptr %64, i64 %63
  store ptr %65, ptr %3, align 8, !tbaa !5
  %66 = load i64, ptr %4, align 8, !tbaa !9
  %67 = sub i64 %66, %63
  store i64 %67, ptr %4, align 8, !tbaa !9
  br label %68

68:                                               ; preds = %.thread, %59, %53, %40, %34, %28, %23, %14
  %.0 = phi i32 [ 0, %23 ], [ -1, %28 ], [ -1, %34 ], [ -1, %40 ], [ -1, %53 ], [ -1, %59 ], [ 1, %.thread ], [ -1, %14 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #3
  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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 }
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 = !{!"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 = !{!7, !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass