; 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_int_from_der_ex = external hidden unnamed_addr constant [21 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_integer_from_der_ex(i32 noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #2

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

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

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

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

27:                                               ; preds = %24, %20, %17, %4
  br label %28

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

31:                                               ; preds = %28
  br label %32

32:                                               ; preds = %31
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %92

33:                                               ; preds = %24
  %34 = load i32, ptr %6, align 4, !tbaa !5
  %35 = load ptr, ptr %8, align 8, !tbaa !9
  %36 = load ptr, ptr %9, align 8, !tbaa !9
  %37 = call i32 @asn1_integer_from_der_ex(i32 noundef %34, ptr noundef %11, ptr noundef %12, ptr noundef %35, ptr noundef %36)
  store i32 %37, ptr %10, align 4, !tbaa !5
  %38 = icmp ne i32 %37, 1
  br i1 %38, label %39, label %52

39:                                               ; preds = %33
  %40 = load i32, ptr %10, align 4, !tbaa !5
  %41 = icmp slt i32 %40, 0
  br i1 %41, label %42, label %48

42:                                               ; preds = %39
  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 669, ptr noundef @__FUNCTION__.asn1_int_from_der_ex) #3
  br label %46

46:                                               ; preds = %43
  br label %47

47:                                               ; preds = %46
  br label %50

48:                                               ; preds = %39
  %49 = load ptr, ptr %7, align 8, !tbaa !9
  store i32 -1, ptr %49, align 4, !tbaa !5
  br label %50

50:                                               ; preds = %48, %47
  %51 = load i32, ptr %10, align 4, !tbaa !5
  store i32 %51, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %92

52:                                               ; preds = %33
  %53 = load i64, ptr %12, align 8, !tbaa !11
  %54 = icmp ugt i64 %53, 4
  br i1 %54, label %55, label %61

55:                                               ; preds = %52
  br label %56

56:                                               ; preds = %55
  %57 = load ptr, ptr @stderr, align 8, !tbaa !9
  %58 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %57, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 674, ptr noundef @__FUNCTION__.asn1_int_from_der_ex) #3
  br label %59

59:                                               ; preds = %56
  br label %60

60:                                               ; preds = %59
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %92

61:                                               ; preds = %52
  %62 = load ptr, ptr %7, align 8, !tbaa !9
  store i32 0, ptr %62, align 4, !tbaa !5
  store i64 0, ptr %13, align 8, !tbaa !11
  br label %63

63:                                               ; preds = %78, %61
  %64 = load i64, ptr %13, align 8, !tbaa !11
  %65 = load i64, ptr %12, align 8, !tbaa !11
  %66 = icmp ult i64 %64, %65
  br i1 %66, label %67, label %81

67:                                               ; preds = %63
  %68 = load ptr, ptr %7, align 8, !tbaa !9
  %69 = load i32, ptr %68, align 4, !tbaa !5
  %70 = shl i32 %69, 8
  %71 = load ptr, ptr %11, align 8, !tbaa !9
  %72 = load i64, ptr %13, align 8, !tbaa !11
  %73 = getelementptr inbounds i8, ptr %71, i64 %72
  %74 = load i8, ptr %73, align 1, !tbaa !13
  %75 = zext i8 %74 to i32
  %76 = or i32 %70, %75
  %77 = load ptr, ptr %7, align 8, !tbaa !9
  store i32 %76, ptr %77, align 4, !tbaa !5
  br label %78

78:                                               ; preds = %67
  %79 = load i64, ptr %13, align 8, !tbaa !11
  %80 = add i64 %79, 1
  store i64 %80, ptr %13, align 8, !tbaa !11
  br label %63, !llvm.loop !14

81:                                               ; preds = %63
  %82 = load ptr, ptr %7, align 8, !tbaa !9
  %83 = load i32, ptr %82, align 4, !tbaa !5
  %84 = icmp slt i32 %83, 0
  br i1 %84, label %85, label %91

85:                                               ; preds = %81
  br label %86

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

89:                                               ; preds = %86
  br label %90

90:                                               ; preds = %89
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %92

91:                                               ; preds = %81
  store i32 1, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %92

92:                                               ; preds = %91, %90, %60, %50, %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %93 = load i32, ptr %5, align 4
  ret i32 %93
}

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}
!14 = distinct !{!14, !15}
!15 = !{!"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_int_from_der_ex = external hidden unnamed_addr constant [21 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_integer_from_der_ex(i32 noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local i32 @asn1_int_from_der_ex(i32 noundef %0, ptr noundef writeonly %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #2 {
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #3
  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
  br i1 %or.cond, label %9, label %13

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

13:                                               ; preds = %4, %9
  %14 = load ptr, ptr @stderr, align 8, !tbaa !5
  %15 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %14, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 664, ptr noundef nonnull @__FUNCTION__.asn1_int_from_der_ex) #4
  br label %._crit_edge.thread

16:                                               ; preds = %9
  %17 = call i32 @asn1_integer_from_der_ex(i32 noundef %0, ptr noundef nonnull %5, ptr noundef nonnull %6, ptr noundef nonnull %2, ptr noundef nonnull %3)
  %.not = icmp eq i32 %17, 1
  br i1 %.not, label %24, label %18

18:                                               ; preds = %16
  %19 = icmp slt i32 %17, 0
  br i1 %19, label %20, label %23

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 669, ptr noundef nonnull @__FUNCTION__.asn1_int_from_der_ex) #4
  br label %._crit_edge.thread

23:                                               ; preds = %18
  store i32 -1, ptr %1, align 4, !tbaa !9
  br label %._crit_edge.thread

24:                                               ; preds = %16
  %25 = load i64, ptr %6, align 8, !tbaa !11
  %26 = icmp ugt i64 %25, 4
  br i1 %26, label %27, label %30

27:                                               ; preds = %24
  %28 = load ptr, ptr @stderr, align 8, !tbaa !5
  %29 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %28, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 674, ptr noundef nonnull @__FUNCTION__.asn1_int_from_der_ex) #4
  br label %._crit_edge.thread

30:                                               ; preds = %24
  store i32 0, ptr %1, align 4, !tbaa !9
  %.not26 = icmp eq i64 %25, 0
  br i1 %.not26, label %._crit_edge.thread, label %.lr.ph

.lr.ph:                                           ; preds = %30
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = load i8, ptr %31, align 1, !tbaa !13
  %33 = zext i8 %32 to i32
  store i32 %33, ptr %1, align 4, !tbaa !9
  %exitcond.not = icmp eq i64 %25, 1
  br i1 %exitcond.not, label %._crit_edge.thread, label %34, !llvm.loop !14

34:                                               ; preds = %.lr.ph
  %35 = shl nuw nsw i32 %33, 8
  %36 = getelementptr inbounds i8, ptr %31, i64 1
  %37 = load i8, ptr %36, align 1, !tbaa !13
  %38 = zext i8 %37 to i32
  %39 = or disjoint i32 %35, %38
  store i32 %39, ptr %1, align 4, !tbaa !9
  %exitcond.not.1 = icmp eq i64 %25, 2
  br i1 %exitcond.not.1, label %._crit_edge.thread, label %40, !llvm.loop !14

40:                                               ; preds = %34
  %41 = shl nuw nsw i32 %39, 8
  %42 = getelementptr inbounds i8, ptr %31, i64 2
  %43 = load i8, ptr %42, align 1, !tbaa !13
  %44 = zext i8 %43 to i32
  %45 = or disjoint i32 %41, %44
  store i32 %45, ptr %1, align 4, !tbaa !9
  %exitcond.not.2 = icmp eq i64 %25, 3
  br i1 %exitcond.not.2, label %._crit_edge.thread, label %._crit_edge, !llvm.loop !14

._crit_edge:                                      ; preds = %40
  %46 = shl nuw i32 %45, 8
  %47 = getelementptr inbounds i8, ptr %31, i64 3
  %48 = load i8, ptr %47, align 1, !tbaa !13
  %49 = zext i8 %48 to i32
  %50 = or disjoint i32 %46, %49
  store i32 %50, ptr %1, align 4, !tbaa !9
  %51 = icmp slt i32 %46, 0
  br i1 %51, label %52, label %._crit_edge.thread

52:                                               ; preds = %._crit_edge
  %53 = load ptr, ptr @stderr, align 8, !tbaa !5
  %54 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %53, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 683, ptr noundef nonnull @__FUNCTION__.asn1_int_from_der_ex) #4
  br label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %.lr.ph, %34, %40, %30, %._crit_edge, %20, %23, %52, %27, %13
  %.020 = phi i32 [ -1, %27 ], [ -1, %52 ], [ -1, %13 ], [ %17, %23 ], [ %17, %20 ], [ 1, %._crit_edge ], [ 1, %30 ], [ 1, %40 ], [ 1, %34 ], [ 1, %.lr.ph ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #3
  ret i32 %.020
}

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass