; 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_type_to_der = external hidden unnamed_addr constant [17 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @asn1_type_to_der(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
  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
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  %13 = icmp ne ptr %12, null
  br i1 %13, label %19, label %14

14:                                               ; preds = %5
  br label %15

15:                                               ; preds = %14
  %16 = load ptr, ptr @stderr, align 8, !tbaa !9
  %17 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %16, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 287, ptr noundef @__FUNCTION__.asn1_type_to_der) #3
  br label %18

18:                                               ; preds = %15
  store i32 -1, ptr %6, align 4
  br label %72

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

22:                                               ; preds = %19
  %23 = load i64, ptr %9, align 8, !tbaa !11
  %24 = icmp ne i64 %23, 0
  br i1 %24, label %25, label %30

25:                                               ; preds = %22
  br label %26

26:                                               ; preds = %25
  %27 = load ptr, ptr @stderr, align 8, !tbaa !9
  %28 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %27, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 293, ptr noundef @__FUNCTION__.asn1_type_to_der) #3
  br label %29

29:                                               ; preds = %26
  store i32 -1, ptr %6, align 4
  br label %72

30:                                               ; preds = %22
  store i32 0, ptr %6, align 4
  br label %72

31:                                               ; preds = %19
  %32 = load ptr, ptr %10, align 8, !tbaa !9
  %33 = icmp ne ptr %32, null
  br i1 %33, label %34, label %44

34:                                               ; preds = %31
  %35 = load ptr, ptr %10, align 8, !tbaa !9
  %36 = load ptr, ptr %35, align 8, !tbaa !9
  %37 = icmp ne ptr %36, null
  br i1 %37, label %38, label %44

38:                                               ; preds = %34
  %39 = load i32, ptr %7, align 4, !tbaa !5
  %40 = trunc i32 %39 to i8
  %41 = load ptr, ptr %10, align 8, !tbaa !9
  %42 = load ptr, ptr %41, align 8, !tbaa !9
  %43 = getelementptr inbounds i8, ptr %42, i32 1
  store ptr %43, ptr %41, align 8, !tbaa !9
  store i8 %40, ptr %42, align 1, !tbaa !13
  br label %44

44:                                               ; preds = %38, %34, %31
  %45 = load ptr, ptr %11, align 8, !tbaa !9
  %46 = load i64, ptr %45, align 8, !tbaa !11
  %47 = add i64 %46, 1
  store i64 %47, ptr %45, align 8, !tbaa !11
  %48 = load i64, ptr %9, align 8, !tbaa !11
  %49 = load ptr, ptr %10, align 8, !tbaa !9
  %50 = load ptr, ptr %11, align 8, !tbaa !9
  %51 = call i32 @asn1_length_to_der(i64 noundef %48, ptr noundef %49, ptr noundef %50)
  %52 = load ptr, ptr %10, align 8, !tbaa !9
  %53 = icmp ne ptr %52, null
  br i1 %53, label %54, label %67

54:                                               ; preds = %44
  %55 = load ptr, ptr %10, align 8, !tbaa !9
  %56 = load ptr, ptr %55, align 8, !tbaa !9
  %57 = icmp ne ptr %56, null
  br i1 %57, label %58, label %67

58:                                               ; preds = %54
  %59 = load ptr, ptr %10, align 8, !tbaa !9
  %60 = load ptr, ptr %59, align 8, !tbaa !9
  %61 = load ptr, ptr %8, align 8, !tbaa !9
  %62 = load i64, ptr %9, align 8, !tbaa !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %60, ptr align 1 %61, i64 %62, i1 false)
  %63 = load i64, ptr %9, align 8, !tbaa !11
  %64 = load ptr, ptr %10, align 8, !tbaa !9
  %65 = load ptr, ptr %64, align 8, !tbaa !9
  %66 = getelementptr inbounds i8, ptr %65, i64 %63
  store ptr %66, ptr %64, align 8, !tbaa !9
  br label %67

67:                                               ; preds = %58, %54, %44
  %68 = load i64, ptr %9, align 8, !tbaa !11
  %69 = load ptr, ptr %11, align 8, !tbaa !9
  %70 = load i64, ptr %69, align 8, !tbaa !11
  %71 = add i64 %70, %68
  store i64 %71, ptr %69, align 8, !tbaa !11
  store i32 1, ptr %6, align 4
  br label %72

72:                                               ; preds = %67, %30, %29, %18
  %73 = load i32, ptr %6, align 4
  ret i32 %73
}

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 nounwind willreturn memory(argmem: readwrite) }
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_type_to_der = external hidden unnamed_addr constant [17 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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

6:                                                ; preds = %5
  %7 = load ptr, ptr @stderr, align 8, !tbaa !5
  %8 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %7, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 287, ptr noundef nonnull @__FUNCTION__.asn1_type_to_der) #3
  br label %34

9:                                                ; preds = %5
  %.not25 = icmp eq ptr %1, null
  br i1 %.not25, label %10, label %14

10:                                               ; preds = %9
  %.not26 = icmp eq i64 %2, 0
  br i1 %.not26, label %34, label %11

11:                                               ; preds = %10
  %12 = load ptr, ptr @stderr, align 8, !tbaa !5
  %13 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %12, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 293, ptr noundef nonnull @__FUNCTION__.asn1_type_to_der) #3
  br label %34

14:                                               ; preds = %9
  %.not27 = icmp eq ptr %3, null
  br i1 %.not27, label %.critedge, label %15

15:                                               ; preds = %14
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %.not28 = icmp eq ptr %16, null
  br i1 %.not28, label %20, label %17

17:                                               ; preds = %15
  %18 = trunc i32 %0 to i8
  %19 = getelementptr inbounds i8, ptr %16, i64 1
  store ptr %19, ptr %3, align 8, !tbaa !5
  store i8 %18, ptr %16, align 1, !tbaa !9
  br label %20

20:                                               ; preds = %15, %17
  %21 = load i64, ptr %4, align 8, !tbaa !10
  %22 = add i64 %21, 1
  store i64 %22, ptr %4, align 8, !tbaa !10
  %23 = tail call i32 @asn1_length_to_der(i64 noundef %2, ptr noundef nonnull %3, ptr noundef nonnull %4)
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %.not29 = icmp eq ptr %24, null
  br i1 %.not29, label %31, label %25

25:                                               ; preds = %20
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %24, ptr nonnull align 1 %1, i64 %2, i1 false)
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %26, i64 %2
  store ptr %27, ptr %3, align 8, !tbaa !5
  br label %31

.critedge:                                        ; preds = %14
  %28 = load i64, ptr %4, align 8, !tbaa !10
  %29 = add i64 %28, 1
  store i64 %29, ptr %4, align 8, !tbaa !10
  %30 = tail call i32 @asn1_length_to_der(i64 noundef %2, ptr noundef null, ptr noundef nonnull %4)
  br label %31

31:                                               ; preds = %.critedge, %25, %20
  %32 = load i64, ptr %4, align 8, !tbaa !10
  %33 = add i64 %32, %2
  store i64 %33, ptr %4, align 8, !tbaa !10
  br label %34

34:                                               ; preds = %10, %31, %11, %6
  %.0 = phi i32 [ 1, %31 ], [ -1, %11 ], [ -1, %6 ], [ 0, %10 ]
  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 nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"long", !7, i64 0}


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