; 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_sequence_of_int_from_der = external hidden unnamed_addr constant [30 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_type_from_der(i32 noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #2

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

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

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

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

25:                                               ; preds = %22, %19, %5
  br label %26

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

29:                                               ; preds = %26
  br label %30

30:                                               ; preds = %29
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %83

31:                                               ; preds = %22
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  store i64 0, ptr %32, align 8, !tbaa !9
  %33 = load ptr, ptr %10, align 8, !tbaa !5
  %34 = load ptr, ptr %11, align 8, !tbaa !5
  %35 = call i32 @asn1_type_from_der(i32 noundef 48, ptr noundef %13, ptr noundef %14, ptr noundef %33, ptr noundef %34)
  store i32 %35, ptr %12, align 4, !tbaa !11
  %36 = icmp ne i32 %35, 1
  br i1 %36, label %37, label %48

37:                                               ; preds = %31
  %38 = load i32, ptr %12, align 4, !tbaa !11
  %39 = icmp slt i32 %38, 0
  br i1 %39, label %40, label %46

40:                                               ; preds = %37
  br label %41

41:                                               ; preds = %40
  %42 = load ptr, ptr @stderr, align 8, !tbaa !5
  %43 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %42, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 1829, ptr noundef @__FUNCTION__.asn1_sequence_of_int_from_der) #3
  br label %44

44:                                               ; preds = %41
  br label %45

45:                                               ; preds = %44
  br label %46

46:                                               ; preds = %45, %37
  %47 = load i32, ptr %12, align 4, !tbaa !11
  store i32 %47, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %83

48:                                               ; preds = %31
  br label %49

49:                                               ; preds = %81, %48
  %50 = load i64, ptr %14, align 8, !tbaa !9
  %51 = icmp ne i64 %50, 0
  br i1 %51, label %52, label %82

52:                                               ; preds = %49
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  %53 = load ptr, ptr %8, align 8, !tbaa !5
  %54 = load i64, ptr %53, align 8, !tbaa !9
  %55 = load i64, ptr %9, align 8, !tbaa !9
  %56 = icmp ugt i64 %54, %55
  br i1 %56, label %57, label %63

57:                                               ; preds = %52
  br label %58

58:                                               ; preds = %57
  %59 = load ptr, ptr @stderr, align 8, !tbaa !5
  %60 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %59, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 1835, ptr noundef @__FUNCTION__.asn1_sequence_of_int_from_der) #3
  br label %61

61:                                               ; preds = %58
  br label %62

62:                                               ; preds = %61
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %79

63:                                               ; preds = %52
  %64 = call i32 @asn1_int_from_der_ex(i32 noundef 2, ptr noundef %16, ptr noundef %13, ptr noundef %14)
  %65 = icmp ne i32 %64, 1
  br i1 %65, label %66, label %72

66:                                               ; preds = %63
  br label %67

67:                                               ; preds = %66
  %68 = load ptr, ptr @stderr, align 8, !tbaa !5
  %69 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %68, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 1839, ptr noundef @__FUNCTION__.asn1_sequence_of_int_from_der) #3
  br label %70

70:                                               ; preds = %67
  br label %71

71:                                               ; preds = %70
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %79

72:                                               ; preds = %63
  %73 = load i32, ptr %16, align 4, !tbaa !11
  %74 = load ptr, ptr %7, align 8, !tbaa !5
  %75 = getelementptr inbounds i32, ptr %74, i32 1
  store ptr %75, ptr %7, align 8, !tbaa !5
  store i32 %73, ptr %74, align 4, !tbaa !11
  %76 = load ptr, ptr %8, align 8, !tbaa !5
  %77 = load i64, ptr %76, align 8, !tbaa !9
  %78 = add i64 %77, 1
  store i64 %78, ptr %76, align 8, !tbaa !9
  store i32 0, ptr %15, align 4
  br label %79

79:                                               ; preds = %72, %71, %62
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  %80 = load i32, ptr %15, align 4
  switch i32 %80, label %83 [
    i32 0, label %81
  ]

81:                                               ; preds = %79
  br label %49, !llvm.loop !13

82:                                               ; preds = %49
  store i32 1, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %83

83:                                               ; preds = %82, %79, %46, %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  %84 = load i32, ptr %6, align 4
  ret i32 %84
}

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 = !{!"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 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; 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_sequence_of_int_from_der = external hidden unnamed_addr constant [30 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_type_from_der(i32 noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

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

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

12:                                               ; preds = %5
  %13 = load ptr, ptr @stderr, align 8, !tbaa !5
  %14 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %13, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 1823, ptr noundef nonnull @__FUNCTION__.asn1_sequence_of_int_from_der) #4
  br label %.loopexit

15:                                               ; preds = %5
  store i64 0, ptr %1, align 8, !tbaa !9
  %16 = call i32 @asn1_type_from_der(i32 noundef 48, ptr noundef nonnull %6, ptr noundef nonnull %7, ptr noundef %3, ptr noundef %4)
  %.not = icmp eq i32 %16, 1
  br i1 %.not, label %.preheader, label %18

.preheader:                                       ; preds = %15
  %17 = load i64, ptr %7, align 8, !tbaa !9
  %.not2327 = icmp eq i64 %17, 0
  br i1 %.not2327, label %.loopexit, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.preheader
  %.pre = load i64, ptr %1, align 8, !tbaa !9
  br label %.lr.ph

18:                                               ; preds = %15
  %19 = icmp slt i32 %16, 0
  br i1 %19, label %20, label %.loopexit

20:                                               ; preds = %18
  %21 = load ptr, ptr @stderr, align 8, !tbaa !5
  %22 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %21, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 1829, ptr noundef nonnull @__FUNCTION__.asn1_sequence_of_int_from_der) #4
  br label %.loopexit

.lr.ph:                                           ; preds = %.lr.ph.preheader, %29
  %23 = phi i64 [ %33, %29 ], [ %.pre, %.lr.ph.preheader ]
  %.01728 = phi ptr [ %31, %29 ], [ %0, %.lr.ph.preheader ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %8) #3
  %24 = icmp ugt i64 %23, %2
  br i1 %24, label %.thread, label %25

25:                                               ; preds = %.lr.ph
  %26 = call i32 @asn1_int_from_der_ex(i32 noundef 2, ptr noundef nonnull %8, ptr noundef nonnull %6, ptr noundef nonnull %7)
  %.not24 = icmp eq i32 %26, 1
  br i1 %.not24, label %29, label %.thread

.thread:                                          ; preds = %25, %.lr.ph
  %.sink29 = phi i32 [ 1835, %.lr.ph ], [ 1839, %25 ]
  %27 = load ptr, ptr @stderr, align 8, !tbaa !5
  %28 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %27, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef %.sink29, ptr noundef nonnull @__FUNCTION__.asn1_sequence_of_int_from_der) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %8) #3
  br label %.loopexit

29:                                               ; preds = %25
  %30 = load i32, ptr %8, align 4, !tbaa !11
  %31 = getelementptr inbounds i8, ptr %.01728, i64 4
  store i32 %30, ptr %.01728, align 4, !tbaa !11
  %32 = load i64, ptr %1, align 8, !tbaa !9
  %33 = add i64 %32, 1
  store i64 %33, ptr %1, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %8) #3
  %34 = load i64, ptr %7, align 8, !tbaa !9
  %.not23 = icmp eq i64 %34, 0
  br i1 %.not23, label %.loopexit, label %.lr.ph, !llvm.loop !13

.loopexit:                                        ; preds = %29, %.preheader, %.thread, %18, %20, %12
  %.2 = phi i32 [ -1, %12 ], [ %16, %20 ], [ %16, %18 ], [ -1, %.thread ], [ 1, %.preheader ], [ 1, %29 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #3
  ret i32 %.2
}

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 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass