; LLVM IR from yinqiwen/ardb :: src/common/channel/codec (redis_command_codec)

; 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"

@_ZL5kCRLF = external hidden global ptr, align 8
@.str.8 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN4ardb6Buffer16AdvanceReadIndexEi(ptr noundef nonnull align 8 dereferenceable(33), i32 noundef) #1 align 2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNK4ardb6Buffer12GetReadIndexEv(ptr noundef nonnull align 8 dereferenceable(33)) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN4ardb5codec19RedisCommandDecoder19ProcessInlineBufferERNS_6BufferERNS0_17RedisCommandFrameE(ptr noundef nonnull align 8 dereferenceable(33) %0, ptr noundef nonnull align 8 dereferenceable(160) %1) #2 align 2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i8, align 1
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = load ptr, ptr @_ZL5kCRLF, align 8, !tbaa !5
  %14 = call noundef i32 @_ZN4ardb6Buffer7IndexOfEPKvm(ptr noundef nonnull align 8 dereferenceable(33) %12, ptr noundef %13, i64 noundef 2)
  store i32 %14, ptr %6, align 4, !tbaa !9
  %15 = load i32, ptr %6, align 4, !tbaa !9
  %16 = icmp eq i32 -1, %15
  br i1 %16, label %17, label %18

17:                                               ; preds = %2
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %78

18:                                               ; preds = %2
  br label %19

19:                                               ; preds = %61, %59, %18
  br label %20

20:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #5
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = call noundef zeroext i1 @_ZN4ardb6Buffer8ReadByteERc(ptr noundef nonnull align 8 dereferenceable(33) %21, ptr noundef nonnull align 1 dereferenceable(1) %8)
  br i1 %22, label %24, label %23

23:                                               ; preds = %20
  store i32 3, ptr %7, align 4
  br label %59

24:                                               ; preds = %20
  %25 = load i8, ptr %8, align 1, !tbaa !11
  %26 = sext i8 %25 to i32
  %27 = icmp eq i32 %26, 32
  br i1 %27, label %28, label %29

28:                                               ; preds = %24
  store i32 2, ptr %7, align 4
  br label %59, !llvm.loop !12

29:                                               ; preds = %24
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZN4ardb6Buffer16AdvanceReadIndexEi(ptr noundef nonnull align 8 dereferenceable(33) %30, i32 noundef -1)
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = call noundef i64 @_ZNK4ardb6Buffer12GetReadIndexEv(ptr noundef nonnull align 8 dereferenceable(33) %31)
  %33 = trunc i64 %32 to i32
  store i32 %33, ptr %9, align 4, !tbaa !9
  %34 = load i32, ptr %9, align 4, !tbaa !9
  %35 = load i32, ptr %6, align 4, !tbaa !9
  %36 = icmp eq i32 %34, %35
  br i1 %36, label %37, label %39

37:                                               ; preds = %29
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZN4ardb6Buffer16AdvanceReadIndexEi(ptr noundef nonnull align 8 dereferenceable(33) %38, i32 noundef 2)
  store i32 3, ptr %7, align 4
  br label %58

39:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = load i32, ptr %9, align 4, !tbaa !9
  %42 = sext i32 %41 to i64
  %43 = load i32, ptr %6, align 4, !tbaa !9
  %44 = sext i32 %43 to i64
  %45 = call noundef i32 @_ZN4ardb6Buffer7IndexOfEPKvmmm(ptr noundef nonnull align 8 dereferenceable(33) %40, ptr noundef @.str.8, i64 noundef 1, i64 noundef %42, i64 noundef %44)
  store i32 %45, ptr %10, align 4, !tbaa !9
  %46 = load i32, ptr %10, align 4, !tbaa !9
  %47 = icmp eq i32 -1, %46
  br i1 %47, label %48, label %49

48:                                               ; preds = %39
  store i32 3, ptr %7, align 4
  br label %57

49:                                               ; preds = %39
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = load i32, ptr %10, align 4, !tbaa !9
  %53 = load i32, ptr %9, align 4, !tbaa !9
  %54 = sub nsw i32 %52, %53
  %55 = sext i32 %54 to i64
  call void @_ZN4ardb5codec17RedisCommandFrame16FillNextArgumentERNS_6BufferEm(ptr noundef nonnull align 8 dereferenceable(160) %50, ptr noundef nonnull align 8 dereferenceable(33) %51, i64 noundef %55)
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZN4ardb6Buffer16AdvanceReadIndexEi(ptr noundef nonnull align 8 dereferenceable(33) %56, i32 noundef 1)
  store i32 0, ptr %7, align 4
  br label %57

57:                                               ; preds = %49, %48
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  br label %58

58:                                               ; preds = %57, %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  br label %59

59:                                               ; preds = %58, %28, %23
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #5
  %60 = load i32, ptr %7, align 4
  switch i32 %60, label %80 [
    i32 0, label %61
    i32 3, label %62
    i32 2, label %19
  ]

61:                                               ; preds = %59
  br label %19, !llvm.loop !12

62:                                               ; preds = %59
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = call noundef i64 @_ZNK4ardb6Buffer12GetReadIndexEv(ptr noundef nonnull align 8 dereferenceable(33) %63)
  %65 = trunc i64 %64 to i32
  store i32 %65, ptr %11, align 4, !tbaa !9
  %66 = load i32, ptr %11, align 4, !tbaa !9
  %67 = load i32, ptr %6, align 4, !tbaa !9
  %68 = icmp slt i32 %66, %67
  br i1 %68, label %69, label %77

69:                                               ; preds = %62
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = load i32, ptr %6, align 4, !tbaa !9
  %73 = load i32, ptr %11, align 4, !tbaa !9
  %74 = sub nsw i32 %72, %73
  %75 = sext i32 %74 to i64
  call void @_ZN4ardb5codec17RedisCommandFrame16FillNextArgumentERNS_6BufferEm(ptr noundef nonnull align 8 dereferenceable(160) %70, ptr noundef nonnull align 8 dereferenceable(33) %71, i64 noundef %75)
  %76 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZN4ardb6Buffer16AdvanceReadIndexEi(ptr noundef nonnull align 8 dereferenceable(33) %76, i32 noundef 2)
  br label %77

77:                                               ; preds = %69, %62
  store i32 1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  br label %78

78:                                               ; preds = %77, %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  %79 = load i32, ptr %3, align 4
  ret i32 %79

80:                                               ; preds = %59
  unreachable
}

declare noundef i32 @_ZN4ardb6Buffer7IndexOfEPKvm(ptr noundef nonnull align 8 dereferenceable(33), ptr noundef, i64 noundef) #3

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN4ardb6Buffer8ReadByteERc(ptr noundef nonnull align 8 dereferenceable(33), ptr noundef nonnull align 1 dereferenceable(1)) #4 align 2

declare noundef i32 @_ZN4ardb6Buffer7IndexOfEPKvmmm(ptr noundef nonnull align 8 dereferenceable(33), ptr noundef, i64 noundef, i64 noundef, i64 noundef) #3

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN4ardb5codec17RedisCommandFrame16FillNextArgumentERNS_6BufferEm(ptr noundef nonnull align 8 dereferenceable(160), ptr noundef nonnull align 8 dereferenceable(33), i64 noundef) #4 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint mustprogress 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 = { mustprogress 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 = { "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 #4 = { inlinehint mustprogress 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 #5 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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"

@_ZL5kCRLF = external hidden local_unnamed_addr global ptr, align 8
@.str.8 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN4ardb6Buffer16AdvanceReadIndexEi(ptr noundef nonnull align 8 dereferenceable(33), i32 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNK4ardb6Buffer12GetReadIndexEv(ptr noundef nonnull align 8 dereferenceable(33)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 0, 2) i32 @_ZN4ardb5codec19RedisCommandDecoder19ProcessInlineBufferERNS_6BufferERNS0_17RedisCommandFrameE(ptr noundef nonnull align 8 dereferenceable(33) %0, ptr noundef nonnull align 8 dereferenceable(160) %1) local_unnamed_addr #2 align 2 {
  %3 = alloca i8, align 1
  %4 = load ptr, ptr @_ZL5kCRLF, align 8, !tbaa !5
  %5 = tail call noundef i32 @_ZN4ardb6Buffer7IndexOfEPKvm(ptr noundef nonnull align 8 dereferenceable(33) %0, ptr noundef %4, i64 noundef 2)
  %6 = icmp eq i32 %5, -1
  br i1 %6, label %32, label %.preheader

.preheader:                                       ; preds = %2
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %3) #5
  %7 = call noundef zeroext i1 @_ZN4ardb6Buffer8ReadByteERc(ptr noundef nonnull align 8 dereferenceable(33) %0, ptr noundef nonnull align 1 dereferenceable(1) %3)
  br i1 %7, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader
  %8 = sext i32 %5 to i64
  br label %9

9:                                                ; preds = %.lr.ph, %24
  %10 = load i8, ptr %3, align 1, !tbaa !9
  %11 = icmp eq i8 %10, 32
  br i1 %11, label %24, label %12, !llvm.loop !10

12:                                               ; preds = %9
  call void @_ZN4ardb6Buffer16AdvanceReadIndexEi(ptr noundef nonnull align 8 dereferenceable(33) %0, i32 noundef -1)
  %13 = call noundef i64 @_ZNK4ardb6Buffer12GetReadIndexEv(ptr noundef nonnull align 8 dereferenceable(33) %0)
  %14 = trunc i64 %13 to i32
  %15 = icmp eq i32 %5, %14
  br i1 %15, label %16, label %17

16:                                               ; preds = %12
  call void @_ZN4ardb6Buffer16AdvanceReadIndexEi(ptr noundef nonnull align 8 dereferenceable(33) %0, i32 noundef 2)
  br label %.loopexit

17:                                               ; preds = %12
  %sext = shl i64 %13, 32
  %18 = ashr exact i64 %sext, 32
  %19 = call noundef i32 @_ZN4ardb6Buffer7IndexOfEPKvmmm(ptr noundef nonnull align 8 dereferenceable(33) %0, ptr noundef nonnull @.str.8, i64 noundef 1, i64 noundef %18, i64 noundef %8)
  %20 = icmp eq i32 %19, -1
  br i1 %20, label %.loopexit, label %21

21:                                               ; preds = %17
  %22 = sub nsw i32 %19, %14
  %23 = sext i32 %22 to i64
  call void @_ZN4ardb5codec17RedisCommandFrame16FillNextArgumentERNS_6BufferEm(ptr noundef nonnull align 8 dereferenceable(160) %1, ptr noundef nonnull align 8 dereferenceable(33) %0, i64 noundef %23)
  call void @_ZN4ardb6Buffer16AdvanceReadIndexEi(ptr noundef nonnull align 8 dereferenceable(33) %0, i32 noundef 1)
  br label %24

24:                                               ; preds = %21, %9
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %3) #5
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %3) #5
  %25 = call noundef zeroext i1 @_ZN4ardb6Buffer8ReadByteERc(ptr noundef nonnull align 8 dereferenceable(33) %0, ptr noundef nonnull align 1 dereferenceable(1) %3)
  br i1 %25, label %9, label %.loopexit

.loopexit:                                        ; preds = %17, %24, %.preheader, %16
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %3) #5
  %26 = call noundef i64 @_ZNK4ardb6Buffer12GetReadIndexEv(ptr noundef nonnull align 8 dereferenceable(33) %0)
  %27 = trunc i64 %26 to i32
  %28 = icmp sgt i32 %5, %27
  br i1 %28, label %29, label %32

29:                                               ; preds = %.loopexit
  %30 = sub nsw i32 %5, %27
  %31 = sext i32 %30 to i64
  call void @_ZN4ardb5codec17RedisCommandFrame16FillNextArgumentERNS_6BufferEm(ptr noundef nonnull align 8 dereferenceable(160) %1, ptr noundef nonnull align 8 dereferenceable(33) %0, i64 noundef %31)
  call void @_ZN4ardb6Buffer16AdvanceReadIndexEi(ptr noundef nonnull align 8 dereferenceable(33) %0, i32 noundef 2)
  br label %32

32:                                               ; preds = %.loopexit, %29, %2
  %.0 = phi i32 [ 0, %2 ], [ 1, %29 ], [ 1, %.loopexit ]
  ret i32 %.0
}

declare noundef i32 @_ZN4ardb6Buffer7IndexOfEPKvm(ptr noundef nonnull align 8 dereferenceable(33), ptr noundef, i64 noundef) local_unnamed_addr #3

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN4ardb6Buffer8ReadByteERc(ptr noundef nonnull align 8 dereferenceable(33), ptr noundef nonnull align 1 dereferenceable(1)) local_unnamed_addr #4 align 2

declare noundef i32 @_ZN4ardb6Buffer7IndexOfEPKvmmm(ptr noundef nonnull align 8 dereferenceable(33), ptr noundef, i64 noundef, i64 noundef, i64 noundef) local_unnamed_addr #3

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN4ardb5codec17RedisCommandFrame16FillNextArgumentERNS_6BufferEm(ptr noundef nonnull align 8 dereferenceable(160), ptr noundef nonnull align 8 dereferenceable(33), i64 noundef) local_unnamed_addr #4 align 2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint mustprogress 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 = { mustprogress 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 = { "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 #4 = { inlinehint mustprogress 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 #5 = { 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++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


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