; 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_bits_from_der_ex = external hidden unnamed_addr constant [22 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_bit_string_from_der_ex(i32 noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @asn1_bits_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 i8, align 1
  %13 = alloca i64, align 8
  %14 = alloca i64, align 8
  %15 = 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 1, 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
  %16 = load ptr, ptr %7, align 8, !tbaa !9
  %17 = icmp ne ptr %16, null
  br i1 %17, label %24, label %18

18:                                               ; preds = %4
  br label %19

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

22:                                               ; preds = %19
  br label %23

23:                                               ; preds = %22
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %15, align 4
  br label %85

24:                                               ; preds = %4
  %25 = load i32, ptr %6, align 4, !tbaa !5
  %26 = load ptr, ptr %8, align 8, !tbaa !9
  %27 = load ptr, ptr %9, align 8, !tbaa !9
  %28 = call i32 @asn1_bit_string_from_der_ex(i32 noundef %25, ptr noundef %11, ptr noundef %13, ptr noundef %26, ptr noundef %27)
  store i32 %28, ptr %10, align 4, !tbaa !5
  %29 = icmp ne i32 %28, 1
  br i1 %29, label %30, label %43

30:                                               ; preds = %24
  %31 = load i32, ptr %10, align 4, !tbaa !5
  %32 = icmp slt i32 %31, 0
  br i1 %32, label %33, label %39

33:                                               ; preds = %30
  br label %34

34:                                               ; preds = %33
  %35 = load ptr, ptr @stderr, align 8, !tbaa !9
  %36 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %35, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 865, ptr noundef @__FUNCTION__.asn1_bits_from_der_ex) #3
  br label %37

37:                                               ; preds = %34
  br label %38

38:                                               ; preds = %37
  br label %41

39:                                               ; preds = %30
  %40 = load ptr, ptr %7, align 8, !tbaa !9
  store i32 -1, ptr %40, align 4, !tbaa !5
  br label %41

41:                                               ; preds = %39, %38
  %42 = load i32, ptr %10, align 4, !tbaa !5
  store i32 %42, ptr %5, align 4
  store i32 1, ptr %15, align 4
  br label %85

43:                                               ; preds = %24
  %44 = load i64, ptr %13, align 8, !tbaa !11
  %45 = icmp ugt i64 %44, 31
  br i1 %45, label %46, label %52

46:                                               ; preds = %43
  br label %47

47:                                               ; preds = %46
  %48 = load ptr, ptr @stderr, align 8, !tbaa !9
  %49 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %48, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 871, ptr noundef @__FUNCTION__.asn1_bits_from_der_ex) #3
  br label %50

50:                                               ; preds = %47
  br label %51

51:                                               ; preds = %50
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %15, align 4
  br label %85

52:                                               ; preds = %43
  %53 = load ptr, ptr %7, align 8, !tbaa !9
  store i32 0, ptr %53, align 4, !tbaa !5
  store i64 0, ptr %14, align 8, !tbaa !11
  br label %54

54:                                               ; preds = %81, %52
  %55 = load i64, ptr %14, align 8, !tbaa !11
  %56 = load i64, ptr %13, align 8, !tbaa !11
  %57 = icmp ult i64 %55, %56
  br i1 %57, label %58, label %84

58:                                               ; preds = %54
  %59 = load i64, ptr %14, align 8, !tbaa !11
  %60 = urem i64 %59, 8
  %61 = icmp eq i64 %60, 0
  br i1 %61, label %62, label %66

62:                                               ; preds = %58
  %63 = load ptr, ptr %11, align 8, !tbaa !9
  %64 = getelementptr inbounds i8, ptr %63, i32 1
  store ptr %64, ptr %11, align 8, !tbaa !9
  %65 = load i8, ptr %63, align 1, !tbaa !13
  store i8 %65, ptr %12, align 1, !tbaa !13
  br label %66

66:                                               ; preds = %62, %58
  %67 = load i8, ptr %12, align 1, !tbaa !13
  %68 = zext i8 %67 to i32
  %69 = and i32 %68, 128
  %70 = ashr i32 %69, 7
  %71 = load i64, ptr %14, align 8, !tbaa !11
  %72 = trunc i64 %71 to i32
  %73 = shl i32 %70, %72
  %74 = load ptr, ptr %7, align 8, !tbaa !9
  %75 = load i32, ptr %74, align 4, !tbaa !5
  %76 = or i32 %75, %73
  store i32 %76, ptr %74, align 4, !tbaa !5
  %77 = load i8, ptr %12, align 1, !tbaa !13
  %78 = zext i8 %77 to i32
  %79 = shl i32 %78, 1
  %80 = trunc i32 %79 to i8
  store i8 %80, ptr %12, align 1, !tbaa !13
  br label %81

81:                                               ; preds = %66
  %82 = load i64, ptr %14, align 8, !tbaa !11
  %83 = add i64 %82, 1
  store i64 %83, ptr %14, align 8, !tbaa !11
  br label %54, !llvm.loop !14

84:                                               ; preds = %54
  store i32 1, ptr %5, align 4
  store i32 1, ptr %15, align 4
  br label %85

85:                                               ; preds = %84, %51, %41, %23
  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 1, 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
  %86 = load i32, ptr %5, align 4
  ret i32 %86
}

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_bits_from_der_ex = external hidden unnamed_addr constant [22 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_bit_string_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_bits_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
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %7, label %10

7:                                                ; preds = %4
  %8 = load ptr, ptr @stderr, align 8, !tbaa !5
  %9 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %8, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 860, ptr noundef nonnull @__FUNCTION__.asn1_bits_from_der_ex) #4
  br label %.loopexit

10:                                               ; preds = %4
  %11 = call i32 @asn1_bit_string_from_der_ex(i32 noundef %0, ptr noundef nonnull %5, ptr noundef nonnull %6, ptr noundef %2, ptr noundef %3)
  %.not19 = icmp eq i32 %11, 1
  br i1 %.not19, label %18, label %12

12:                                               ; preds = %10
  %13 = icmp slt i32 %11, 0
  br i1 %13, label %14, label %17

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

17:                                               ; preds = %12
  store i32 -1, ptr %1, align 4, !tbaa !9
  br label %.loopexit

18:                                               ; preds = %10
  %19 = load i64, ptr %6, align 8, !tbaa !11
  %20 = icmp ugt i64 %19, 31
  br i1 %20, label %21, label %24

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

24:                                               ; preds = %18
  store i32 0, ptr %1, align 4, !tbaa !9
  %.not23 = icmp eq i64 %19, 0
  br i1 %.not23, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %24
  %.promoted = load ptr, ptr %5, align 8, !tbaa !5
  %xtraiter = and i64 %19, 1
  %25 = icmp eq i64 %19, 1
  br i1 %25, label %.loopexit.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %19, 30
  br label %26

26:                                               ; preds = %34, %.lr.ph.new
  %27 = phi i32 [ 0, %.lr.ph.new ], [ %47, %34 ]
  %.021 = phi i64 [ 0, %.lr.ph.new ], [ %49, %34 ]
  %.01520 = phi i8 [ undef, %.lr.ph.new ], [ %48, %34 ]
  %28 = phi ptr [ %.promoted, %.lr.ph.new ], [ %35, %34 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %34 ]
  %29 = and i64 %.021, 6
  %30 = icmp eq i64 %29, 0
  br i1 %30, label %31, label %34

31:                                               ; preds = %26
  %32 = getelementptr inbounds i8, ptr %28, i64 1
  store ptr %32, ptr %5, align 8, !tbaa !5
  %33 = load i8, ptr %28, align 1, !tbaa !13
  br label %34

34:                                               ; preds = %31, %26
  %35 = phi ptr [ %32, %31 ], [ %28, %26 ]
  %.1 = phi i8 [ %33, %31 ], [ %.01520, %26 ]
  %36 = lshr i8 %.1, 7
  %37 = zext nneg i8 %36 to i32
  %38 = trunc i64 %.021 to i32
  %39 = shl nuw i32 %37, %38
  %40 = or i32 %39, %27
  store i32 %40, ptr %1, align 4, !tbaa !9
  %41 = lshr i8 %.1, 6
  %42 = and i8 %41, 1
  %43 = zext nneg i8 %42 to i32
  %44 = trunc i64 %.021 to i32
  %45 = or disjoint i32 %44, 1
  %46 = shl nuw i32 %43, %45
  %47 = or i32 %46, %40
  store i32 %47, ptr %1, align 4, !tbaa !9
  %48 = shl i8 %.1, 2
  %49 = add nuw i64 %.021, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %.loopexit.loopexit.unr-lcssa, label %26, !llvm.loop !14

.loopexit.loopexit.unr-lcssa:                     ; preds = %34, %.lr.ph
  %.unr = phi i32 [ 0, %.lr.ph ], [ %47, %34 ]
  %.021.unr = phi i64 [ 0, %.lr.ph ], [ %49, %34 ]
  %.01520.unr = phi i8 [ undef, %.lr.ph ], [ %48, %34 ]
  %.unr24 = phi ptr [ %.promoted, %.lr.ph ], [ %35, %34 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.loopexit, label %.epil.preheader

.epil.preheader:                                  ; preds = %.loopexit.loopexit.unr-lcssa
  %50 = and i64 %.021.unr, 7
  %51 = icmp eq i64 %50, 0
  br i1 %51, label %52, label %.loopexit.loopexit.epilog-lcssa

52:                                               ; preds = %.epil.preheader
  %53 = getelementptr inbounds i8, ptr %.unr24, i64 1
  store ptr %53, ptr %5, align 8, !tbaa !5
  %54 = load i8, ptr %.unr24, align 1, !tbaa !13
  br label %.loopexit.loopexit.epilog-lcssa

.loopexit.loopexit.epilog-lcssa:                  ; preds = %52, %.epil.preheader
  %.1.epil = phi i8 [ %54, %52 ], [ %.01520.unr, %.epil.preheader ]
  %55 = lshr i8 %.1.epil, 7
  %56 = zext nneg i8 %55 to i32
  %57 = trunc i64 %.021.unr to i32
  %58 = shl nuw i32 %56, %57
  %59 = or i32 %58, %.unr
  store i32 %59, ptr %1, align 4, !tbaa !9
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit.epilog-lcssa, %.loopexit.loopexit.unr-lcssa, %24, %14, %17, %21, %7
  %.016 = phi i32 [ -1, %21 ], [ -1, %7 ], [ %11, %17 ], [ %11, %14 ], [ 1, %24 ], [ 1, %.loopexit.loopexit.unr-lcssa ], [ 1, %.loopexit.loopexit.epilog-lcssa ]
  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 %.016
}

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,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass