; 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_bit_string_from_der_ex = external hidden unnamed_addr constant [28 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_bit_string_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
  %14 = 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
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %15 = load ptr, ptr %8, align 8, !tbaa !9
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %30

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

20:                                               ; preds = %17
  %21 = load ptr, ptr %10, align 8, !tbaa !9
  %22 = icmp ne ptr %21, null
  br i1 %22, label %23, label %30

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

27:                                               ; preds = %23
  %28 = load ptr, ptr %11, align 8, !tbaa !9
  %29 = icmp ne ptr %28, null
  br i1 %29, label %36, label %30

30:                                               ; preds = %27, %23, %20, %17, %5
  br label %31

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

34:                                               ; preds = %31
  br label %35

35:                                               ; preds = %34
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %115

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

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

47:                                               ; preds = %40, %36
  %48 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr null, ptr %48, align 8, !tbaa !9
  %49 = load ptr, ptr %9, align 8, !tbaa !9
  store i64 0, ptr %49, align 8, !tbaa !11
  store i32 0, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %115

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

61:                                               ; preds = %50
  br label %62

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

65:                                               ; preds = %62
  br label %66

66:                                               ; preds = %65
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %115

67:                                               ; preds = %50
  %68 = load i64, ptr %12, align 8, !tbaa !11
  %69 = icmp ult i64 %68, 2
  br i1 %69, label %70, label %76

70:                                               ; preds = %67
  br label %71

71:                                               ; preds = %70
  %72 = load ptr, ptr @stderr, align 8, !tbaa !9
  %73 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %72, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 757, ptr noundef @__FUNCTION__.asn1_bit_string_from_der_ex) #3
  br label %74

74:                                               ; preds = %71
  br label %75

75:                                               ; preds = %74
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %115

76:                                               ; preds = %67
  %77 = load ptr, ptr %10, align 8, !tbaa !9
  %78 = load ptr, ptr %77, align 8, !tbaa !9
  %79 = load i8, ptr %78, align 1, !tbaa !13
  %80 = zext i8 %79 to i32
  store i32 %80, ptr %13, align 4, !tbaa !5
  %81 = load i32, ptr %13, align 4, !tbaa !5
  %82 = icmp sgt i32 %81, 7
  br i1 %82, label %83, label %89

83:                                               ; preds = %76
  br label %84

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

87:                                               ; preds = %84
  br label %88

88:                                               ; preds = %87
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %115

89:                                               ; preds = %76
  %90 = load ptr, ptr %10, align 8, !tbaa !9
  %91 = load ptr, ptr %90, align 8, !tbaa !9
  %92 = getelementptr inbounds i8, ptr %91, i32 1
  store ptr %92, ptr %90, align 8, !tbaa !9
  %93 = load ptr, ptr %11, align 8, !tbaa !9
  %94 = load i64, ptr %93, align 8, !tbaa !11
  %95 = add i64 %94, -1
  store i64 %95, ptr %93, align 8, !tbaa !11
  %96 = load i64, ptr %12, align 8, !tbaa !11
  %97 = add i64 %96, -1
  store i64 %97, ptr %12, align 8, !tbaa !11
  %98 = load ptr, ptr %10, align 8, !tbaa !9
  %99 = load ptr, ptr %98, align 8, !tbaa !9
  %100 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %99, ptr %100, align 8, !tbaa !9
  %101 = load i64, ptr %12, align 8, !tbaa !11
  %102 = shl i64 %101, 3
  %103 = load i32, ptr %13, align 4, !tbaa !5
  %104 = sext i32 %103 to i64
  %105 = sub i64 %102, %104
  %106 = load ptr, ptr %9, align 8, !tbaa !9
  store i64 %105, ptr %106, align 8, !tbaa !11
  %107 = load i64, ptr %12, align 8, !tbaa !11
  %108 = load ptr, ptr %10, align 8, !tbaa !9
  %109 = load ptr, ptr %108, align 8, !tbaa !9
  %110 = getelementptr inbounds i8, ptr %109, i64 %107
  store ptr %110, ptr %108, align 8, !tbaa !9
  %111 = load i64, ptr %12, align 8, !tbaa !11
  %112 = load ptr, ptr %11, align 8, !tbaa !9
  %113 = load i64, ptr %112, align 8, !tbaa !11
  %114 = sub i64 %113, %111
  store i64 %114, ptr %112, align 8, !tbaa !11
  store i32 1, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %115

115:                                              ; preds = %89, %88, %75, %66, %47, %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  %116 = load i32, ptr %6, align 4
  ret i32 %116
}

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_bit_string_from_der_ex = external hidden unnamed_addr constant [28 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_bit_string_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 738, ptr noundef nonnull @__FUNCTION__.asn1_bit_string_from_der_ex) #4
  br label %56

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 %56

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)
  %.not35 = icmp eq i32 %27, 1
  br i1 %.not35, 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 753, ptr noundef nonnull @__FUNCTION__.asn1_bit_string_from_der_ex) #4
  br label %56

31:                                               ; preds = %24
  %32 = load i64, ptr %6, align 8, !tbaa !9
  %33 = icmp ult i64 %32, 2
  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 757, ptr noundef nonnull @__FUNCTION__.asn1_bit_string_from_der_ex) #4
  br label %56

37:                                               ; preds = %31
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = load i8, ptr %38, align 1, !tbaa !11
  %40 = icmp ugt i8 %39, 7
  br i1 %40, label %41, label %44

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

44:                                               ; preds = %37
  %45 = getelementptr inbounds i8, ptr %38, i64 1
  store ptr %45, ptr %3, align 8, !tbaa !5
  %46 = load i64, ptr %4, align 8, !tbaa !9
  %47 = add i64 %46, -1
  store i64 %47, ptr %4, align 8, !tbaa !9
  %48 = add i64 %32, -1
  store ptr %45, ptr %1, align 8, !tbaa !5
  %49 = shl i64 %48, 3
  %50 = zext nneg i8 %39 to i64
  %51 = sub i64 %49, %50
  store i64 %51, ptr %2, align 8, !tbaa !9
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds i8, ptr %52, i64 %48
  store ptr %53, ptr %3, align 8, !tbaa !5
  %54 = load i64, ptr %4, align 8, !tbaa !9
  %55 = sub i64 %54, %48
  store i64 %55, ptr %4, align 8, !tbaa !9
  br label %56

56:                                               ; preds = %44, %41, %34, %28, %23, %14
  %.0 = phi i32 [ 0, %23 ], [ -1, %28 ], [ -1, %34 ], [ -1, %41 ], [ 1, %44 ], [ -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: DSEPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass