; 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_from_octets = external hidden unnamed_addr constant [35 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
define dso_local i32 @asn1_object_identifier_from_octets(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3) #2 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i64 %3, ptr %9, align 8, !tbaa !9
  %12 = load ptr, ptr %7, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %20

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

17:                                               ; preds = %14
  %18 = load i64, ptr %9, align 8, !tbaa !9
  %19 = icmp ne i64 %18, 0
  br i1 %19, label %25, label %20

20:                                               ; preds = %17, %14, %4
  br label %21

21:                                               ; preds = %20
  %22 = load ptr, ptr @stderr, align 8, !tbaa !5
  %23 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %22, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 1029, ptr noundef @__FUNCTION__.asn1_object_identifier_from_octets) #3
  br label %24

24:                                               ; preds = %21
  store i32 -1, ptr %5, align 4
  br label %84

25:                                               ; preds = %17
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = icmp ne ptr %26, null
  br i1 %27, label %28, label %41

28:                                               ; preds = %25
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  %30 = load i8, ptr %29, align 1, !tbaa !11
  %31 = zext i8 %30 to i32
  %32 = sdiv i32 %31, 40
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = getelementptr inbounds i32, ptr %33, i32 1
  store ptr %34, ptr %6, align 8, !tbaa !5
  store i32 %32, ptr %33, align 4, !tbaa !12
  %35 = load ptr, ptr %8, align 8, !tbaa !5
  %36 = load i8, ptr %35, align 1, !tbaa !11
  %37 = zext i8 %36 to i32
  %38 = srem i32 %37, 40
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds i32, ptr %39, i32 1
  store ptr %40, ptr %6, align 8, !tbaa !5
  store i32 %38, ptr %39, align 4, !tbaa !12
  br label %41

41:                                               ; preds = %28, %25
  %42 = load ptr, ptr %8, align 8, !tbaa !5
  %43 = getelementptr inbounds i8, ptr %42, i32 1
  store ptr %43, ptr %8, align 8, !tbaa !5
  %44 = load i64, ptr %9, align 8, !tbaa !9
  %45 = add i64 %44, -1
  store i64 %45, ptr %9, align 8, !tbaa !9
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  store i64 2, ptr %46, align 8, !tbaa !9
  br label %47

47:                                               ; preds = %82, %41
  %48 = load i64, ptr %9, align 8, !tbaa !9
  %49 = icmp ne i64 %48, 0
  br i1 %49, label %50, label %83

50:                                               ; preds = %47
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = load i64, ptr %51, align 8, !tbaa !9
  %53 = icmp ugt i64 %52, 32
  br i1 %53, label %54, label %60

54:                                               ; preds = %50
  br label %55

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

58:                                               ; preds = %55
  br label %59

59:                                               ; preds = %58
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %80

60:                                               ; preds = %50
  %61 = call i32 @asn1_oid_node_from_base128(ptr noundef %10, ptr noundef %8, ptr noundef %9)
  %62 = icmp slt i32 %61, 0
  br i1 %62, label %63, label %69

63:                                               ; preds = %60
  br label %64

64:                                               ; preds = %63
  %65 = load ptr, ptr @stderr, align 8, !tbaa !5
  %66 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %65, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 1048, ptr noundef @__FUNCTION__.asn1_object_identifier_from_octets) #3
  br label %67

67:                                               ; preds = %64
  br label %68

68:                                               ; preds = %67
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %80

69:                                               ; preds = %60
  %70 = load ptr, ptr %6, align 8, !tbaa !5
  %71 = icmp ne ptr %70, null
  br i1 %71, label %72, label %76

72:                                               ; preds = %69
  %73 = load i32, ptr %10, align 4, !tbaa !12
  %74 = load ptr, ptr %6, align 8, !tbaa !5
  %75 = getelementptr inbounds i32, ptr %74, i32 1
  store ptr %75, ptr %6, align 8, !tbaa !5
  store i32 %73, ptr %74, align 4, !tbaa !12
  br label %76

76:                                               ; preds = %72, %69
  %77 = load ptr, ptr %7, align 8, !tbaa !5
  %78 = load i64, ptr %77, align 8, !tbaa !9
  %79 = add i64 %78, 1
  store i64 %79, ptr %77, align 8, !tbaa !9
  store i32 0, ptr %11, align 4
  br label %80

80:                                               ; preds = %76, %68, %59
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %81 = load i32, ptr %11, align 4
  switch i32 %81, label %86 [
    i32 0, label %82
    i32 1, label %84
  ]

82:                                               ; preds = %80
  br label %47, !llvm.loop !14

83:                                               ; preds = %47
  store i32 1, ptr %5, align 4
  br label %84

84:                                               ; preds = %83, %80, %24
  %85 = load i32, ptr %5, align 4
  ret i32 %85

86:                                               ; preds = %80
  unreachable
}

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

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 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !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_from_octets = external hidden unnamed_addr constant [35 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
define dso_local noundef i32 @asn1_object_identifier_from_octets(ptr noundef writeonly %0, ptr noundef %1, ptr noundef %2, i64 noundef %3) local_unnamed_addr #2 {
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = icmp ne ptr %1, null
  %9 = icmp ne ptr %2, null
  %or.cond = and i1 %8, %9
  %10 = icmp ne i64 %3, 0
  %or.cond3 = and i1 %or.cond, %10
  br i1 %or.cond3, label %14, label %11

11:                                               ; preds = %4
  %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 1029, ptr noundef nonnull @__FUNCTION__.asn1_object_identifier_from_octets) #3
  br label %.loopexit

14:                                               ; preds = %4
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %24, label %15

15:                                               ; preds = %14
  %16 = load i8, ptr %2, align 1, !tbaa !9
  %17 = udiv i8 %16, 40
  %18 = zext nneg i8 %17 to i32
  %19 = getelementptr inbounds i8, ptr %0, i64 4
  store i32 %18, ptr %0, align 4, !tbaa !10
  %20 = load i8, ptr %2, align 1, !tbaa !9
  %21 = urem i8 %20, 40
  %22 = zext nneg i8 %21 to i32
  %23 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 %22, ptr %19, align 4, !tbaa !10
  br label %24

24:                                               ; preds = %15, %14
  %.014 = phi ptr [ %23, %15 ], [ null, %14 ]
  %25 = getelementptr inbounds i8, ptr %2, i64 1
  store ptr %25, ptr %5, align 8, !tbaa !5
  %26 = add i64 %3, -1
  store i64 %26, ptr %6, align 8, !tbaa !12
  store i64 2, ptr %1, align 8, !tbaa !12
  %.not2126 = icmp eq i64 %26, 0
  br i1 %.not2126, label %.loopexit, label %.lr.ph

thread-pre-split:                                 ; preds = %35, %34
  %.216 = phi ptr [ %37, %35 ], [ null, %34 ]
  %27 = load i64, ptr %1, align 8, !tbaa !12
  %28 = add i64 %27, 1
  store i64 %28, ptr %1, align 8, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %7) #4
  %.pr = load i64, ptr %6, align 8, !tbaa !12
  %.not21 = icmp eq i64 %.pr, 0
  br i1 %.not21, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %24, %thread-pre-split
  %29 = phi i64 [ %28, %thread-pre-split ], [ 2, %24 ]
  %.11527 = phi ptr [ %.216, %thread-pre-split ], [ %.014, %24 ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %7) #4
  %30 = icmp ugt i64 %29, 32
  br i1 %30, label %.thread, label %31

31:                                               ; preds = %.lr.ph
  %32 = call i32 @asn1_oid_node_from_base128(ptr noundef nonnull %7, ptr noundef nonnull %5, ptr noundef nonnull %6)
  %33 = icmp slt i32 %32, 0
  br i1 %33, label %.thread, label %34

34:                                               ; preds = %31
  %.not22 = icmp eq ptr %.11527, null
  br i1 %.not22, label %thread-pre-split, label %35

35:                                               ; preds = %34
  %36 = load i32, ptr %7, align 4, !tbaa !10
  %37 = getelementptr inbounds i8, ptr %.11527, i64 4
  store i32 %36, ptr %.11527, align 4, !tbaa !10
  br label %thread-pre-split

.thread:                                          ; preds = %31, %.lr.ph
  %.sink28 = phi i32 [ 1044, %.lr.ph ], [ 1048, %31 ]
  %38 = load ptr, ptr @stderr, align 8, !tbaa !5
  %39 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %38, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef %.sink28, ptr noundef nonnull @__FUNCTION__.asn1_object_identifier_from_octets) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %7) #4
  br label %.loopexit

.loopexit:                                        ; preds = %thread-pre-split, %24, %.thread, %11
  %.2 = phi i32 [ -1, %11 ], [ -1, %.thread ], [ 1, %24 ], [ 1, %thread-pre-split ]
  ret i32 %.2
}

; Function Attrs: nounwind uwtable
declare hidden i32 @asn1_oid_node_from_base128(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #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 = { cold nounwind }
attributes #4 = { 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 = !{!"int", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"long", !7, i64 0}


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