; 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_octets = 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
define dso_local i32 @asn1_object_identifier_to_octets(ptr noundef %0, i64 noundef %1, ptr noundef %2, ptr noundef %3) #1 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  %10 = load ptr, ptr %6, align 8, !tbaa !5
  %11 = icmp ne ptr %10, null
  br i1 %11, label %12, label %15

12:                                               ; preds = %4
  %13 = load ptr, ptr %9, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %20, label %15

15:                                               ; preds = %12, %4
  br label %16

16:                                               ; preds = %15
  %17 = load ptr, ptr @stderr, align 8, !tbaa !5
  %18 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %17, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 1006, ptr noundef @__FUNCTION__.asn1_object_identifier_to_octets) #2
  br label %19

19:                                               ; preds = %16
  store i32 -1, ptr %5, align 4
  br label %62

20:                                               ; preds = %12
  %21 = load i64, ptr %7, align 8, !tbaa !9
  %22 = icmp ult i64 %21, 2
  br i1 %22, label %26, label %23

23:                                               ; preds = %20
  %24 = load i64, ptr %7, align 8, !tbaa !9
  %25 = icmp ugt i64 %24, 32
  br i1 %25, label %26, label %31

26:                                               ; preds = %23, %20
  br label %27

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

30:                                               ; preds = %27
  store i32 -1, ptr %5, align 4
  br label %62

31:                                               ; preds = %23
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = icmp ne ptr %32, null
  br i1 %33, label %34, label %46

34:                                               ; preds = %31
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = getelementptr inbounds i32, ptr %35, i64 0
  %37 = load i32, ptr %36, align 4, !tbaa !11
  %38 = mul i32 %37, 40
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds i32, ptr %39, i64 1
  %41 = load i32, ptr %40, align 4, !tbaa !11
  %42 = add i32 %38, %41
  %43 = trunc i32 %42 to i8
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  %45 = getelementptr inbounds i8, ptr %44, i32 1
  store ptr %45, ptr %8, align 8, !tbaa !5
  store i8 %43, ptr %44, align 1, !tbaa !13
  br label %46

46:                                               ; preds = %34, %31
  %47 = load ptr, ptr %9, align 8, !tbaa !5
  store i64 1, ptr %47, align 8, !tbaa !9
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = getelementptr inbounds i32, ptr %48, i64 2
  store ptr %49, ptr %6, align 8, !tbaa !5
  %50 = load i64, ptr %7, align 8, !tbaa !9
  %51 = sub i64 %50, 2
  store i64 %51, ptr %7, align 8, !tbaa !9
  br label %52

52:                                               ; preds = %56, %46
  %53 = load i64, ptr %7, align 8, !tbaa !9
  %54 = add i64 %53, -1
  store i64 %54, ptr %7, align 8, !tbaa !9
  %55 = icmp ne i64 %53, 0
  br i1 %55, label %56, label %61

56:                                               ; preds = %52
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = getelementptr inbounds i32, ptr %57, i32 1
  store ptr %58, ptr %6, align 8, !tbaa !5
  %59 = load i32, ptr %57, align 4, !tbaa !11
  %60 = load ptr, ptr %9, align 8, !tbaa !5
  call void @asn1_oid_node_to_base128(i32 noundef %59, ptr noundef %8, ptr noundef %60)
  br label %52, !llvm.loop !14

61:                                               ; preds = %52
  store i32 1, ptr %5, align 4
  br label %62

62:                                               ; preds = %61, %30, %19
  %63 = load i32, ptr %5, align 4
  ret i32 %63
}

; Function Attrs: nounwind uwtable
declare hidden void @asn1_oid_node_to_base128(i32 noundef, ptr noundef, ptr noundef) #1

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 = { 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 = !{!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_object_identifier_to_octets = 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
define dso_local range(i32 -1, 2) i32 @asn1_object_identifier_to_octets(ptr noundef readonly %0, i64 noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #1 {
  %5 = alloca ptr, align 8
  store ptr %2, ptr %5, align 8, !tbaa !5
  %6 = icmp ne ptr %0, null
  %7 = icmp ne ptr %3, null
  %or.cond = and i1 %6, %7
  br i1 %or.cond, label %8, label %.loopexit.sink.split

8:                                                ; preds = %4
  %9 = add i64 %1, -33
  %or.cond3 = icmp ult i64 %9, -31
  br i1 %or.cond3, label %.loopexit.sink.split, label %10

10:                                               ; preds = %8
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %19, label %11

11:                                               ; preds = %10
  %12 = load i32, ptr %0, align 4, !tbaa !9
  %13 = mul i32 %12, 40
  %14 = getelementptr inbounds i8, ptr %0, i64 4
  %15 = load i32, ptr %14, align 4, !tbaa !9
  %16 = add i32 %13, %15
  %17 = trunc i32 %16 to i8
  %18 = getelementptr inbounds i8, ptr %2, i64 1
  store ptr %18, ptr %5, align 8, !tbaa !5
  store i8 %17, ptr %2, align 1, !tbaa !11
  br label %19

19:                                               ; preds = %11, %10
  store i64 1, ptr %3, align 8, !tbaa !12
  %20 = add nsw i64 %1, -2
  %.not2122 = icmp eq i64 %20, 0
  br i1 %.not2122, label %.loopexit, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %19
  %21 = getelementptr inbounds i8, ptr %0, i64 8
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.01524 = phi i64 [ %22, %.lr.ph ], [ %20, %.lr.ph.preheader ]
  %.01623 = phi ptr [ %23, %.lr.ph ], [ %21, %.lr.ph.preheader ]
  %22 = add i64 %.01524, -1
  %23 = getelementptr inbounds i8, ptr %.01623, i64 4
  %24 = load i32, ptr %.01623, align 4, !tbaa !9
  call void @asn1_oid_node_to_base128(i32 noundef %24, ptr noundef nonnull %5, ptr noundef nonnull %3)
  %.not21 = icmp eq i64 %22, 0
  br i1 %.not21, label %.loopexit, label %.lr.ph, !llvm.loop !14

.loopexit.sink.split:                             ; preds = %8, %4
  %.sink25 = phi i32 [ 1006, %4 ], [ 1010, %8 ]
  %25 = load ptr, ptr @stderr, align 8, !tbaa !5
  %26 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %25, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef %.sink25, ptr noundef nonnull @__FUNCTION__.asn1_object_identifier_to_octets) #2
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %.loopexit.sink.split, %19
  %.0 = phi i32 [ 1, %19 ], [ -1, %.loopexit.sink.split ], [ 1, %.lr.ph ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden void @asn1_oid_node_to_base128(i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

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


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