; 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_object_identifier_to_der_ex = external hidden unnamed_addr constant [33 x i8], align 1

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

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @asn1_object_identifier_to_der_ex(i32 noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, ptr noundef %4) #1 {
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca [151 x i8], align 16
  %13 = alloca i64, align 8
  %14 = alloca i32, align 4
  store i32 %0, ptr %7, align 4, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !9
  store i64 %2, ptr %9, align 8, !tbaa !11
  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 151, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  store i64 0, ptr %13, align 8, !tbaa !11
  %15 = load ptr, ptr %11, align 8, !tbaa !9
  %16 = icmp ne ptr %15, null
  br i1 %16, label %23, label %17

17:                                               ; preds = %5
  br label %18

18:                                               ; preds = %17
  %19 = load ptr, ptr @stderr, align 8, !tbaa !9
  %20 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %19, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 1066, ptr noundef @__FUNCTION__.asn1_object_identifier_to_der_ex) #4
  br label %21

21:                                               ; preds = %18
  br label %22

22:                                               ; preds = %21
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %89

23:                                               ; preds = %5
  %24 = load ptr, ptr %8, align 8, !tbaa !9
  %25 = icmp ne ptr %24, null
  br i1 %25, label %36, label %26

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

29:                                               ; preds = %26
  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 1071, ptr noundef @__FUNCTION__.asn1_object_identifier_to_der_ex) #4
  br label %33

33:                                               ; preds = %30
  br label %34

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

35:                                               ; preds = %26
  store i32 0, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %89

36:                                               ; preds = %23
  %37 = load ptr, ptr %8, align 8, !tbaa !9
  %38 = load i64, ptr %9, align 8, !tbaa !11
  %39 = getelementptr inbounds [151 x i8], ptr %12, i64 0, i64 0
  %40 = call i32 @asn1_object_identifier_to_octets(ptr noundef %37, i64 noundef %38, ptr noundef %39, ptr noundef %13)
  %41 = icmp ne i32 %40, 1
  br i1 %41, label %42, label %48

42:                                               ; preds = %36
  br label %43

43:                                               ; preds = %42
  %44 = load ptr, ptr @stderr, align 8, !tbaa !9
  %45 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %44, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 1078, ptr noundef @__FUNCTION__.asn1_object_identifier_to_der_ex) #4
  br label %46

46:                                               ; preds = %43
  br label %47

47:                                               ; preds = %46
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %89

48:                                               ; preds = %36
  %49 = load ptr, ptr %10, align 8, !tbaa !9
  %50 = icmp ne ptr %49, null
  br i1 %50, label %51, label %61

51:                                               ; preds = %48
  %52 = load ptr, ptr %10, align 8, !tbaa !9
  %53 = load ptr, ptr %52, align 8, !tbaa !9
  %54 = icmp ne ptr %53, null
  br i1 %54, label %55, label %61

55:                                               ; preds = %51
  %56 = load i32, ptr %7, align 4, !tbaa !5
  %57 = trunc i32 %56 to i8
  %58 = load ptr, ptr %10, align 8, !tbaa !9
  %59 = load ptr, ptr %58, align 8, !tbaa !9
  %60 = getelementptr inbounds i8, ptr %59, i32 1
  store ptr %60, ptr %58, align 8, !tbaa !9
  store i8 %57, ptr %59, align 1, !tbaa !13
  br label %61

61:                                               ; preds = %55, %51, %48
  %62 = load ptr, ptr %11, align 8, !tbaa !9
  %63 = load i64, ptr %62, align 8, !tbaa !11
  %64 = add i64 %63, 1
  store i64 %64, ptr %62, align 8, !tbaa !11
  %65 = load i64, ptr %13, align 8, !tbaa !11
  %66 = load ptr, ptr %10, align 8, !tbaa !9
  %67 = load ptr, ptr %11, align 8, !tbaa !9
  %68 = call i32 @asn1_length_to_der(i64 noundef %65, ptr noundef %66, ptr noundef %67)
  %69 = load ptr, ptr %10, align 8, !tbaa !9
  %70 = icmp ne ptr %69, null
  br i1 %70, label %71, label %84

71:                                               ; preds = %61
  %72 = load ptr, ptr %10, align 8, !tbaa !9
  %73 = load ptr, ptr %72, align 8, !tbaa !9
  %74 = icmp ne ptr %73, null
  br i1 %74, label %75, label %84

75:                                               ; preds = %71
  %76 = load ptr, ptr %10, align 8, !tbaa !9
  %77 = load ptr, ptr %76, align 8, !tbaa !9
  %78 = getelementptr inbounds [151 x i8], ptr %12, i64 0, i64 0
  %79 = load i64, ptr %13, align 8, !tbaa !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %77, ptr align 16 %78, i64 %79, i1 false)
  %80 = load i64, ptr %13, align 8, !tbaa !11
  %81 = load ptr, ptr %10, align 8, !tbaa !9
  %82 = load ptr, ptr %81, align 8, !tbaa !9
  %83 = getelementptr inbounds i8, ptr %82, i64 %80
  store ptr %83, ptr %81, align 8, !tbaa !9
  br label %84

84:                                               ; preds = %75, %71, %61
  %85 = load i64, ptr %13, align 8, !tbaa !11
  %86 = load ptr, ptr %11, align 8, !tbaa !9
  %87 = load i64, ptr %86, align 8, !tbaa !11
  %88 = add i64 %87, %85
  store i64 %88, ptr %86, align 8, !tbaa !11
  store i32 1, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %89

89:                                               ; preds = %84, %47, %35, %34, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 151, ptr %12) #4
  %90 = load i32, ptr %6, align 4
  ret i32 %90
}

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"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_object_identifier_to_der_ex = external hidden unnamed_addr constant [33 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 @asn1_length_to_der(i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 2) i32 @asn1_object_identifier_to_der_ex(i32 noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, ptr noundef %4) local_unnamed_addr #1 {
  %6 = alloca [151 x i8], align 16
  %7 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 151, ptr nonnull %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #4
  store i64 0, ptr %7, align 8, !tbaa !5
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %8, label %11

8:                                                ; preds = %5
  %9 = load ptr, ptr @stderr, align 8, !tbaa !9
  %10 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %9, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 1066, ptr noundef nonnull @__FUNCTION__.asn1_object_identifier_to_der_ex) #5
  br label %45

11:                                               ; preds = %5
  %.not22 = icmp eq ptr %1, null
  br i1 %.not22, label %12, label %16

12:                                               ; preds = %11
  %.not23 = icmp eq i64 %2, 0
  br i1 %.not23, label %45, label %13

13:                                               ; preds = %12
  %14 = load ptr, ptr @stderr, align 8, !tbaa !9
  %15 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %14, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 1071, ptr noundef nonnull @__FUNCTION__.asn1_object_identifier_to_der_ex) #5
  br label %45

16:                                               ; preds = %11
  %17 = call i32 @asn1_object_identifier_to_octets(ptr noundef nonnull %1, i64 noundef %2, ptr noundef nonnull %6, ptr noundef nonnull %7)
  %.not24 = icmp eq i32 %17, 1
  br i1 %.not24, label %21, label %18

18:                                               ; preds = %16
  %19 = load ptr, ptr @stderr, align 8, !tbaa !9
  %20 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %19, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 1078, ptr noundef nonnull @__FUNCTION__.asn1_object_identifier_to_der_ex) #5
  br label %45

21:                                               ; preds = %16
  %.not25 = icmp eq ptr %3, null
  br i1 %.not25, label %.critedge, label %22

22:                                               ; preds = %21
  %23 = load ptr, ptr %3, align 8, !tbaa !9
  %.not26 = icmp eq ptr %23, null
  br i1 %.not26, label %27, label %24

24:                                               ; preds = %22
  %25 = trunc i32 %0 to i8
  %26 = getelementptr inbounds i8, ptr %23, i64 1
  store ptr %26, ptr %3, align 8, !tbaa !9
  store i8 %25, ptr %23, align 1, !tbaa !11
  br label %27

27:                                               ; preds = %22, %24
  %28 = load i64, ptr %4, align 8, !tbaa !5
  %29 = add i64 %28, 1
  store i64 %29, ptr %4, align 8, !tbaa !5
  %30 = load i64, ptr %7, align 8, !tbaa !5
  %31 = call i32 @asn1_length_to_der(i64 noundef %30, ptr noundef nonnull %3, ptr noundef nonnull %4)
  %32 = load ptr, ptr %3, align 8, !tbaa !9
  %.not27 = icmp eq ptr %32, null
  %.pre28 = load i64, ptr %7, align 8, !tbaa !5
  br i1 %.not27, label %41, label %33

33:                                               ; preds = %27
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %32, ptr nonnull align 16 %6, i64 %.pre28, i1 false)
  %34 = load i64, ptr %7, align 8, !tbaa !5
  %35 = load ptr, ptr %3, align 8, !tbaa !9
  %36 = getelementptr inbounds i8, ptr %35, i64 %34
  store ptr %36, ptr %3, align 8, !tbaa !9
  br label %41

.critedge:                                        ; preds = %21
  %37 = load i64, ptr %4, align 8, !tbaa !5
  %38 = add i64 %37, 1
  store i64 %38, ptr %4, align 8, !tbaa !5
  %39 = load i64, ptr %7, align 8, !tbaa !5
  %40 = call i32 @asn1_length_to_der(i64 noundef %39, ptr noundef null, ptr noundef nonnull %4)
  %.pre = load i64, ptr %7, align 8, !tbaa !5
  br label %41

41:                                               ; preds = %.critedge, %33, %27
  %42 = phi i64 [ %.pre, %.critedge ], [ %34, %33 ], [ %.pre28, %27 ]
  %43 = load i64, ptr %4, align 8, !tbaa !5
  %44 = add i64 %43, %42
  store i64 %44, ptr %4, align 8, !tbaa !5
  br label %45

45:                                               ; preds = %12, %41, %18, %13, %8
  %.0 = phi i32 [ -1, %18 ], [ 1, %41 ], [ -1, %13 ], [ -1, %8 ], [ 0, %12 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #4
  call void @llvm.lifetime.end.p0(i64 151, ptr nonnull %6) #4
  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 = { 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nounwind }
attributes #5 = { 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 = !{!7, !7, i64 0}


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