; LLVM IR from yinqiwen/ardb :: src/common/channel/codec/redis_reply.ll (ZN4ardb5codec14RedisReplyPool10SetMaxSizeEj)

; 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::RedisReplyPool" = type { i32, i32, %"class.std::vector", %"class.std::deque" }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<ardb::codec::RedisReply, std::allocator<ardb::codec::RedisReply>>::_Vector_impl" }
%"struct.std::_Vector_base<ardb::codec::RedisReply, std::allocator<ardb::codec::RedisReply>>::_Vector_impl" = type { %"struct.std::_Vector_base<ardb::codec::RedisReply, std::allocator<ardb::codec::RedisReply>>::_Vector_impl_data" }
%"struct.std::_Vector_base<ardb::codec::RedisReply, std::allocator<ardb::codec::RedisReply>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::deque" = type { %"class.std::_Deque_base" }
%"class.std::_Deque_base" = type { %"struct.std::_Deque_base<ardb::codec::RedisReply, std::allocator<ardb::codec::RedisReply>>::_Deque_impl" }
%"struct.std::_Deque_base<ardb::codec::RedisReply, std::allocator<ardb::codec::RedisReply>>::_Deque_impl" = type { %"struct.std::_Deque_base<ardb::codec::RedisReply, std::allocator<ardb::codec::RedisReply>>::_Deque_impl_data" }
%"struct.std::_Deque_base<ardb::codec::RedisReply, std::allocator<ardb::codec::RedisReply>>::_Deque_impl_data" = type { ptr, i64, %"struct.std::_Deque_iterator", %"struct.std::_Deque_iterator" }
%"struct.std::_Deque_iterator" = type { ptr, ptr, ptr, ptr }

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4ardb5codec14RedisReplyPool10SetMaxSizeEj(ptr noundef nonnull align 8 dereferenceable(112) %0, i32 noundef %1) #0 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %6 = load ptr, ptr %3, align 8
  %7 = load i32, ptr %4, align 4, !tbaa !9
  %8 = icmp ugt i32 %7, 0
  br i1 %8, label %9, label %35

9:                                                ; preds = %2
  %10 = load i32, ptr %4, align 4, !tbaa !9
  %11 = getelementptr inbounds %"class.ardb::codec::RedisReplyPool", ptr %6, i32 0, i32 0
  %12 = load i32, ptr %11, align 8, !tbaa !11
  %13 = icmp ne i32 %10, %12
  br i1 %13, label %14, label %35

14:                                               ; preds = %9
  %15 = getelementptr inbounds %"class.ardb::codec::RedisReplyPool", ptr %6, i32 0, i32 2
  %16 = load i32, ptr %4, align 4, !tbaa !9
  %17 = zext i32 %16 to i64
  call void @_ZNSt6vectorIN4ardb5codec10RedisReplyESaIS2_EE6resizeEm(ptr noundef nonnull align 8 dereferenceable(24) %15, i64 noundef %17)
  %18 = load i32, ptr %4, align 4, !tbaa !9
  %19 = getelementptr inbounds %"class.ardb::codec::RedisReplyPool", ptr %6, i32 0, i32 0
  store i32 %18, ptr %19, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %20

20:                                               ; preds = %31, %14
  %21 = load i32, ptr %5, align 4, !tbaa !9
  %22 = getelementptr inbounds %"class.ardb::codec::RedisReplyPool", ptr %6, i32 0, i32 0
  %23 = load i32, ptr %22, align 8, !tbaa !11
  %24 = icmp ult i32 %21, %23
  br i1 %24, label %26, label %25

25:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %34

26:                                               ; preds = %20
  %27 = getelementptr inbounds %"class.ardb::codec::RedisReplyPool", ptr %6, i32 0, i32 2
  %28 = load i32, ptr %5, align 4, !tbaa !9
  %29 = zext i32 %28 to i64
  %30 = call noundef nonnull align 8 dereferenceable(72) ptr @_ZNSt6vectorIN4ardb5codec10RedisReplyESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %27, i64 noundef %29) #3
  call void @_ZN4ardb5codec10RedisReply7SetPoolEPNS0_14RedisReplyPoolE(ptr noundef nonnull align 8 dereferenceable(72) %30, ptr noundef %6)
  br label %31

31:                                               ; preds = %26
  %32 = load i32, ptr %5, align 4, !tbaa !9
  %33 = add i32 %32, 1
  store i32 %33, ptr %5, align 4, !tbaa !9
  br label %20, !llvm.loop !23

34:                                               ; preds = %25
  br label %35

35:                                               ; preds = %34, %9, %2
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt6vectorIN4ardb5codec10RedisReplyESaIS2_EE6resizeEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #0 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(72) ptr @_ZNSt6vectorIN4ardb5codec10RedisReplyESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4ardb5codec10RedisReply7SetPoolEPNS0_14RedisReplyPoolE(ptr noundef nonnull align 8 dereferenceable(72), ptr noundef) #2 align 2

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"_ZTSN4ardb5codec14RedisReplyPoolE", !10, i64 0, !10, i64 4, !13, i64 8, !17, i64 32}
!13 = !{!"_ZTSSt6vectorIN4ardb5codec10RedisReplyESaIS2_EE", !14, i64 0}
!14 = !{!"_ZTSSt12_Vector_baseIN4ardb5codec10RedisReplyESaIS2_EE", !15, i64 0}
!15 = !{!"_ZTSNSt12_Vector_baseIN4ardb5codec10RedisReplyESaIS2_EE12_Vector_implE", !16, i64 0}
!16 = !{!"_ZTSNSt12_Vector_baseIN4ardb5codec10RedisReplyESaIS2_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!17 = !{!"_ZTSSt5dequeIN4ardb5codec10RedisReplyESaIS2_EE", !18, i64 0}
!18 = !{!"_ZTSSt11_Deque_baseIN4ardb5codec10RedisReplyESaIS2_EE", !19, i64 0}
!19 = !{!"_ZTSNSt11_Deque_baseIN4ardb5codec10RedisReplyESaIS2_EE11_Deque_implE", !20, i64 0}
!20 = !{!"_ZTSNSt11_Deque_baseIN4ardb5codec10RedisReplyESaIS2_EE16_Deque_impl_dataE", !6, i64 0, !21, i64 8, !22, i64 16, !22, i64 48}
!21 = !{!"long", !7, i64 0}
!22 = !{!"_ZTSSt15_Deque_iteratorIN4ardb5codec10RedisReplyERS2_PS2_E", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!23 = distinct !{!23, !24}
!24 = !{!"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"

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4ardb5codec14RedisReplyPool10SetMaxSizeEj(ptr noundef nonnull align 8 dereferenceable(112) %0, i32 noundef %1) local_unnamed_addr #0 align 2 {
  %.not = icmp eq i32 %1, 0
  %3 = load i32, ptr %0, align 8
  %.not8 = icmp eq i32 %3, %1
  %or.cond = select i1 %.not, i1 true, i1 %.not8
  br i1 %or.cond, label %.loopexit, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %2
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = zext i32 %1 to i64
  tail call void @_ZNSt6vectorIN4ardb5codec10RedisReplyESaIS2_EE6resizeEm(ptr noundef nonnull align 8 dereferenceable(24) %4, i64 noundef %5)
  store i32 %1, ptr %0, align 8, !tbaa !5
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %6 = tail call noundef nonnull align 8 dereferenceable(72) ptr @_ZNSt6vectorIN4ardb5codec10RedisReplyESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %4, i64 noundef %indvars.iv) #2
  tail call void @_ZN4ardb5codec10RedisReply7SetPoolEPNS0_14RedisReplyPoolE(ptr noundef nonnull align 8 dereferenceable(72) %6, ptr noundef nonnull %0)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %7 = load i32, ptr %0, align 8, !tbaa !5
  %8 = zext i32 %7 to i64
  %9 = icmp ult i64 %indvars.iv.next, %8
  br i1 %9, label %.lr.ph, label %.loopexit, !llvm.loop !21

.loopexit:                                        ; preds = %.lr.ph, %2
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt6vectorIN4ardb5codec10RedisReplyESaIS2_EE6resizeEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(72) ptr @_ZNSt6vectorIN4ardb5codec10RedisReplyESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4ardb5codec10RedisReply7SetPoolEPNS0_14RedisReplyPoolE(ptr noundef nonnull align 8 dereferenceable(72), ptr noundef) local_unnamed_addr #1 align 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 = { 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 = { 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, !7, i64 0}
!6 = !{!"_ZTSN4ardb5codec14RedisReplyPoolE", !7, i64 0, !7, i64 4, !10, i64 8, !15, i64 32}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSSt6vectorIN4ardb5codec10RedisReplyESaIS2_EE", !11, i64 0}
!11 = !{!"_ZTSSt12_Vector_baseIN4ardb5codec10RedisReplyESaIS2_EE", !12, i64 0}
!12 = !{!"_ZTSNSt12_Vector_baseIN4ardb5codec10RedisReplyESaIS2_EE12_Vector_implE", !13, i64 0}
!13 = !{!"_ZTSNSt12_Vector_baseIN4ardb5codec10RedisReplyESaIS2_EE17_Vector_impl_dataE", !14, i64 0, !14, i64 8, !14, i64 16}
!14 = !{!"any pointer", !8, i64 0}
!15 = !{!"_ZTSSt5dequeIN4ardb5codec10RedisReplyESaIS2_EE", !16, i64 0}
!16 = !{!"_ZTSSt11_Deque_baseIN4ardb5codec10RedisReplyESaIS2_EE", !17, i64 0}
!17 = !{!"_ZTSNSt11_Deque_baseIN4ardb5codec10RedisReplyESaIS2_EE11_Deque_implE", !18, i64 0}
!18 = !{!"_ZTSNSt11_Deque_baseIN4ardb5codec10RedisReplyESaIS2_EE16_Deque_impl_dataE", !14, i64 0, !19, i64 8, !20, i64 16, !20, i64 48}
!19 = !{!"long", !8, i64 0}
!20 = !{!"_ZTSSt15_Deque_iteratorIN4ardb5codec10RedisReplyERS2_PS2_E", !14, i64 0, !14, i64 8, !14, i64 16, !14, i64 24}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass