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

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

%"class.ardb::codec::IntegerHeaderFrameDecoder" = type <{ %"class.ardb::codec::StackFrameDecoder", i8, i8, i8, [5 x i8] }>
%"class.ardb::codec::StackFrameDecoder" = type { %"class.ardb::ChannelUpstreamHandler", %"class.ardb::Buffer" }
%"class.ardb::ChannelUpstreamHandler" = type { %"class.ardb::AbstractChannelHandler" }
%"class.ardb::AbstractChannelHandler" = type { %"class.ardb::ChannelHandler" }
%"class.ardb::ChannelHandler" = type { ptr }
%"class.ardb::Buffer" = type <{ ptr, i64, i64, i64, i8, [7 x i8] }>

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN4ardb5codec25IntegerHeaderFrameDecoder6DecodeERNS_21ChannelHandlerContextEPNS_7ChannelERNS_6BufferES7_(ptr noundef nonnull align 8 dereferenceable(51) %0, ptr noundef nonnull align 8 dereferenceable(66) %1, ptr noundef %2, ptr noundef nonnull align 8 dereferenceable(33) %3, ptr noundef nonnull align 8 dereferenceable(33) %4) unnamed_addr #0 align 2 {
  %6 = alloca i1, align 1
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !5
  %15 = load ptr, ptr %7, align 8
  %16 = load ptr, ptr %10, align 8, !tbaa !5
  %17 = call noundef i64 @_ZNK4ardb6Buffer13ReadableBytesEv(ptr noundef nonnull align 8 dereferenceable(33) %16)
  %18 = icmp ult i64 %17, 4
  br i1 %18, label %19, label %20

19:                                               ; preds = %5
  store i1 false, ptr %6, align 1
  br label %79

20:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %21 = load ptr, ptr %10, align 8, !tbaa !5
  %22 = call noundef i64 @_ZNK4ardb6Buffer12GetReadIndexEv(ptr noundef nonnull align 8 dereferenceable(33) %21)
  store i64 %22, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %23 = load ptr, ptr %10, align 8, !tbaa !5
  %24 = call noundef i32 @_ZN4ardb6Buffer4ReadEPvm(ptr noundef nonnull align 8 dereferenceable(33) %23, ptr noundef %13, i64 noundef 4)
  %25 = getelementptr inbounds %"class.ardb::codec::IntegerHeaderFrameDecoder", ptr %15, i32 0, i32 1
  %26 = load i8, ptr %25, align 8, !tbaa !11, !range !19, !noundef !20
  %27 = trunc i8 %26 to i1
  br i1 %27, label %28, label %31

28:                                               ; preds = %20
  %29 = load i32, ptr %13, align 4, !tbaa !21
  %30 = call noundef i32 @_ZL10__bswap_32j(i32 noundef %29)
  store i32 %30, ptr %13, align 4, !tbaa !21
  br label %31

31:                                               ; preds = %28, %20
  %32 = load ptr, ptr %10, align 8, !tbaa !5
  %33 = call noundef i64 @_ZNK4ardb6Buffer13ReadableBytesEv(ptr noundef nonnull align 8 dereferenceable(33) %32)
  %34 = load i32, ptr %13, align 4, !tbaa !21
  %35 = zext i32 %34 to i64
  %36 = sub i64 %35, 4
  %37 = icmp ult i64 %33, %36
  br i1 %37, label %38, label %41

38:                                               ; preds = %31
  %39 = load ptr, ptr %10, align 8, !tbaa !5
  %40 = load i64, ptr %12, align 8, !tbaa !9
  call void @_ZN4ardb6Buffer12SetReadIndexEm(ptr noundef nonnull align 8 dereferenceable(33) %39, i64 noundef %40)
  store i1 false, ptr %6, align 1
  store i32 1, ptr %14, align 4
  br label %78

41:                                               ; preds = %31
  %42 = getelementptr inbounds %"class.ardb::codec::IntegerHeaderFrameDecoder", ptr %15, i32 0, i32 3
  %43 = load i8, ptr %42, align 2, !tbaa !23, !range !19, !noundef !20
  %44 = trunc i8 %43 to i1
  br i1 %44, label %48, label %45

45:                                               ; preds = %41
  %46 = load ptr, ptr %11, align 8, !tbaa !5
  %47 = call noundef i32 @_ZN4ardb6Buffer5WriteEPKvm(ptr noundef nonnull align 8 dereferenceable(33) %46, ptr noundef %13, i64 noundef 4)
  br label %48

48:                                               ; preds = %45, %41
  %49 = load ptr, ptr %11, align 8, !tbaa !5
  %50 = getelementptr inbounds %"class.ardb::codec::IntegerHeaderFrameDecoder", ptr %15, i32 0, i32 2
  %51 = load i8, ptr %50, align 1, !tbaa !24, !range !19, !noundef !20
  %52 = trunc i8 %51 to i1
  br i1 %52, label %53, label %57

53:                                               ; preds = %48
  %54 = load i32, ptr %13, align 4, !tbaa !21
  %55 = zext i32 %54 to i64
  %56 = sub i64 %55, 4
  br label %60

57:                                               ; preds = %48
  %58 = load i32, ptr %13, align 4, !tbaa !21
  %59 = zext i32 %58 to i64
  br label %60

60:                                               ; preds = %57, %53
  %61 = phi i64 [ %56, %53 ], [ %59, %57 ]
  %62 = call noundef zeroext i1 @_ZN4ardb6Buffer19EnsureWritableBytesEmb(ptr noundef nonnull align 8 dereferenceable(33) %49, i64 noundef %61, i1 noundef zeroext false)
  %63 = load ptr, ptr %11, align 8, !tbaa !5
  %64 = load ptr, ptr %10, align 8, !tbaa !5
  %65 = getelementptr inbounds %"class.ardb::codec::IntegerHeaderFrameDecoder", ptr %15, i32 0, i32 2
  %66 = load i8, ptr %65, align 1, !tbaa !24, !range !19, !noundef !20
  %67 = trunc i8 %66 to i1
  br i1 %67, label %68, label %72

68:                                               ; preds = %60
  %69 = load i32, ptr %13, align 4, !tbaa !21
  %70 = zext i32 %69 to i64
  %71 = sub i64 %70, 4
  br label %75

72:                                               ; preds = %60
  %73 = load i32, ptr %13, align 4, !tbaa !21
  %74 = zext i32 %73 to i64
  br label %75

75:                                               ; preds = %72, %68
  %76 = phi i64 [ %71, %68 ], [ %74, %72 ]
  %77 = call noundef i32 @_ZN4ardb6Buffer5WriteEPS0_m(ptr noundef nonnull align 8 dereferenceable(33) %63, ptr noundef %64, i64 noundef %76)
  store i1 true, ptr %6, align 1
  store i32 1, ptr %14, align 4
  br label %78

78:                                               ; preds = %75, %38
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  br label %79

79:                                               ; preds = %78, %19
  %80 = load i1, ptr %6, align 1
  ret i1 %80
}

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

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

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef i32 @_ZL10__bswap_32j(i32 noundef) #3

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

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

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

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

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

attributes #0 = { 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 #1 = { 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !18, i64 48}
!12 = !{!"_ZTSN4ardb5codec25IntegerHeaderFrameDecoderE", !13, i64 0, !18, i64 48, !18, i64 49, !18, i64 50}
!13 = !{!"_ZTSN4ardb5codec17StackFrameDecoderINS_6BufferEEE", !14, i64 0, !17, i64 8}
!14 = !{!"_ZTSN4ardb22ChannelUpstreamHandlerINS_6BufferEEE", !15, i64 0}
!15 = !{!"_ZTSN4ardb22AbstractChannelHandlerINS_6BufferEEE", !16, i64 0}
!16 = !{!"_ZTSN4ardb14ChannelHandlerE"}
!17 = !{!"_ZTSN4ardb6BufferE", !6, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !18, i64 32}
!18 = !{!"bool", !7, i64 0}
!19 = !{i8 0, i8 2}
!20 = !{}
!21 = !{!22, !22, i64 0}
!22 = !{!"int", !7, i64 0}
!23 = !{!12, !18, i64 50}
!24 = !{!12, !18, i64 49}


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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN4ardb5codec25IntegerHeaderFrameDecoder6DecodeERNS_21ChannelHandlerContextEPNS_7ChannelERNS_6BufferES7_(ptr nocapture noundef nonnull readonly align 8 dereferenceable(51) %0, ptr nocapture noundef nonnull readnone align 8 dereferenceable(66) %1, ptr nocapture noundef readnone %2, ptr noundef nonnull align 8 dereferenceable(33) %3, ptr noundef nonnull align 8 dereferenceable(33) %4) unnamed_addr #0 align 2 {
  %6 = alloca i32, align 4
  %7 = tail call noundef i64 @_ZNK4ardb6Buffer13ReadableBytesEv(ptr noundef nonnull align 8 dereferenceable(33) %3)
  %8 = icmp ult i64 %7, 4
  br i1 %8, label %45, label %9

9:                                                ; preds = %5
  %10 = tail call noundef i64 @_ZNK4ardb6Buffer12GetReadIndexEv(ptr noundef nonnull align 8 dereferenceable(33) %3)
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #4
  %11 = call noundef i32 @_ZN4ardb6Buffer4ReadEPvm(ptr noundef nonnull align 8 dereferenceable(33) %3, ptr noundef nonnull %6, i64 noundef 4)
  %12 = getelementptr inbounds i8, ptr %0, i64 48
  %13 = load i8, ptr %12, align 8, !tbaa !5, !range !17, !noundef !18
  %14 = trunc nuw i8 %13 to i1
  br i1 %14, label %15, label %18

15:                                               ; preds = %9
  %16 = load i32, ptr %6, align 4, !tbaa !19
  %17 = call noundef i32 @_ZL10__bswap_32j(i32 noundef %16)
  store i32 %17, ptr %6, align 4, !tbaa !19
  br label %18

18:                                               ; preds = %15, %9
  %19 = call noundef i64 @_ZNK4ardb6Buffer13ReadableBytesEv(ptr noundef nonnull align 8 dereferenceable(33) %3)
  %20 = load i32, ptr %6, align 4
  %21 = zext i32 %20 to i64
  %22 = add nsw i64 %21, -4
  %23 = icmp uge i64 %19, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %18
  call void @_ZN4ardb6Buffer12SetReadIndexEm(ptr noundef nonnull align 8 dereferenceable(33) %3, i64 noundef %10)
  br label %44

25:                                               ; preds = %18
  %26 = getelementptr inbounds i8, ptr %0, i64 50
  %27 = load i8, ptr %26, align 2, !tbaa !21, !range !17, !noundef !18
  %28 = trunc nuw i8 %27 to i1
  br i1 %28, label %31, label %29

29:                                               ; preds = %25
  %30 = call noundef i32 @_ZN4ardb6Buffer5WriteEPKvm(ptr noundef nonnull align 8 dereferenceable(33) %4, ptr noundef nonnull %6, i64 noundef 4)
  %.pre = load i32, ptr %6, align 4
  %.pre11 = zext i32 %.pre to i64
  %.pre12 = add nsw i64 %.pre11, -4
  br label %31

31:                                               ; preds = %29, %25
  %.pre-phi13 = phi i64 [ %.pre12, %29 ], [ %22, %25 ]
  %.pre-phi = phi i64 [ %.pre11, %29 ], [ %21, %25 ]
  %32 = getelementptr inbounds i8, ptr %0, i64 49
  %33 = load i8, ptr %32, align 1, !tbaa !22, !range !17, !noundef !18
  %34 = trunc nuw i8 %33 to i1
  %35 = select i1 %34, i64 %.pre-phi13, i64 %.pre-phi
  %36 = call noundef zeroext i1 @_ZN4ardb6Buffer19EnsureWritableBytesEmb(ptr noundef nonnull align 8 dereferenceable(33) %4, i64 noundef %35, i1 noundef zeroext false)
  %37 = load i8, ptr %32, align 1, !tbaa !22, !range !17, !noundef !18
  %38 = trunc nuw i8 %37 to i1
  %39 = load i32, ptr %6, align 4
  %40 = zext i32 %39 to i64
  %41 = add nsw i64 %40, -4
  %42 = select i1 %38, i64 %41, i64 %40
  %43 = call noundef i32 @_ZN4ardb6Buffer5WriteEPS0_m(ptr noundef nonnull align 8 dereferenceable(33) %4, ptr noundef nonnull %3, i64 noundef %42)
  br label %44

44:                                               ; preds = %31, %24
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #4
  br label %45

45:                                               ; preds = %5, %44
  %.1 = phi i1 [ %23, %44 ], [ false, %5 ]
  ret i1 %.1
}

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

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

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef i32 @_ZL10__bswap_32j(i32 noundef) local_unnamed_addr #3

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

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_ZN4ardb6Buffer5WriteEPS0_m(ptr noundef nonnull align 8 dereferenceable(33), ptr noundef, i64 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) #2

attributes #0 = { 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 #1 = { 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 #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #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, !16, i64 48}
!6 = !{!"_ZTSN4ardb5codec25IntegerHeaderFrameDecoderE", !7, i64 0, !16, i64 48, !16, i64 49, !16, i64 50}
!7 = !{!"_ZTSN4ardb5codec17StackFrameDecoderINS_6BufferEEE", !8, i64 0, !11, i64 8}
!8 = !{!"_ZTSN4ardb22ChannelUpstreamHandlerINS_6BufferEEE", !9, i64 0}
!9 = !{!"_ZTSN4ardb22AbstractChannelHandlerINS_6BufferEEE", !10, i64 0}
!10 = !{!"_ZTSN4ardb14ChannelHandlerE"}
!11 = !{!"_ZTSN4ardb6BufferE", !12, i64 0, !15, i64 8, !15, i64 16, !15, i64 24, !16, i64 32}
!12 = !{!"any pointer", !13, i64 0}
!13 = !{!"omnipotent char", !14, i64 0}
!14 = !{!"Simple C++ TBAA"}
!15 = !{!"long", !13, i64 0}
!16 = !{!"bool", !13, i64 0}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = !{!20, !20, i64 0}
!20 = !{!"int", !13, i64 0}
!21 = !{!6, !16, i64 50}
!22 = !{!6, !16, i64 49}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass