; LLVM IR from yinqiwen/ardb :: src/db/codec.ll (ZN4ardb9KeyObject15CloneStringPartEv)

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

%"struct.ardb::KeyObject" = type { %"struct.ardb::Data", i8, [7 x i8], %"struct.ardb::Data", %"class.std::vector" }
%"struct.ardb::Data" = type <{ i64, i32, i8, [3 x i8] }>
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<ardb::Data, std::allocator<ardb::Data>>::_Vector_impl" }
%"struct.std::_Vector_base<ardb::Data, std::allocator<ardb::Data>>::_Vector_impl" = type { %"struct.std::_Vector_base<ardb::Data, std::allocator<ardb::Data>>::_Vector_impl_data" }
%"struct.std::_Vector_base<ardb::Data, std::allocator<ardb::Data>>::_Vector_impl_data" = type { ptr, ptr, ptr }

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

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4ardb9KeyObject15CloneStringPartEv(ptr noundef nonnull align 8 dereferenceable(64) %0) #2 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8
  %5 = getelementptr inbounds %"struct.ardb::KeyObject", ptr %4, i32 0, i32 0
  %6 = call noundef zeroext i1 @_ZNK4ardb4Data8IsStringEv(ptr noundef nonnull align 8 dereferenceable(13) %5)
  br i1 %6, label %7, label %10

7:                                                ; preds = %1
  %8 = getelementptr inbounds %"struct.ardb::KeyObject", ptr %4, i32 0, i32 0
  %9 = call noundef ptr @_ZN4ardb4Data12ToMutableStrEv(ptr noundef nonnull align 8 dereferenceable(13) %8)
  br label %10

10:                                               ; preds = %7, %1
  %11 = getelementptr inbounds %"struct.ardb::KeyObject", ptr %4, i32 0, i32 3
  %12 = call noundef zeroext i1 @_ZNK4ardb4Data8IsStringEv(ptr noundef nonnull align 8 dereferenceable(13) %11)
  br i1 %12, label %13, label %16

13:                                               ; preds = %10
  %14 = getelementptr inbounds %"struct.ardb::KeyObject", ptr %4, i32 0, i32 3
  %15 = call noundef ptr @_ZN4ardb4Data12ToMutableStrEv(ptr noundef nonnull align 8 dereferenceable(13) %14)
  br label %16

16:                                               ; preds = %13, %10
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  store i64 0, ptr %3, align 8, !tbaa !9
  br label %17

17:                                               ; preds = %34, %16
  %18 = load i64, ptr %3, align 8, !tbaa !9
  %19 = getelementptr inbounds %"struct.ardb::KeyObject", ptr %4, i32 0, i32 4
  %20 = call noundef i64 @_ZNKSt6vectorIN4ardb4DataESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %19) #4
  %21 = icmp ult i64 %18, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  br label %37

23:                                               ; preds = %17
  %24 = getelementptr inbounds %"struct.ardb::KeyObject", ptr %4, i32 0, i32 4
  %25 = load i64, ptr %3, align 8, !tbaa !9
  %26 = call noundef nonnull align 8 dereferenceable(13) ptr @_ZNSt6vectorIN4ardb4DataESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %24, i64 noundef %25) #4
  %27 = call noundef zeroext i1 @_ZNK4ardb4Data8IsStringEv(ptr noundef nonnull align 8 dereferenceable(13) %26)
  br i1 %27, label %28, label %33

28:                                               ; preds = %23
  %29 = getelementptr inbounds %"struct.ardb::KeyObject", ptr %4, i32 0, i32 4
  %30 = load i64, ptr %3, align 8, !tbaa !9
  %31 = call noundef nonnull align 8 dereferenceable(13) ptr @_ZNSt6vectorIN4ardb4DataESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %29, i64 noundef %30) #4
  %32 = call noundef ptr @_ZN4ardb4Data12ToMutableStrEv(ptr noundef nonnull align 8 dereferenceable(13) %31)
  br label %33

33:                                               ; preds = %28, %23
  br label %34

34:                                               ; preds = %33
  %35 = load i64, ptr %3, align 8, !tbaa !9
  %36 = add i64 %35, 1
  store i64 %36, ptr %3, align 8, !tbaa !9
  br label %17, !llvm.loop !11

37:                                               ; preds = %22
  ret void
}

declare noundef zeroext i1 @_ZNK4ardb4Data8IsStringEv(ptr noundef nonnull align 8 dereferenceable(13)) #3

declare noundef ptr @_ZN4ardb4Data12ToMutableStrEv(ptr noundef nonnull align 8 dereferenceable(13)) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { 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 = distinct !{!11, !12}
!12 = !{!"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 nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIN4ardb4DataESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4ardb9KeyObject15CloneStringPartEv(ptr noundef nonnull align 8 dereferenceable(64) %0) local_unnamed_addr #1 align 2 {
  %2 = tail call noundef zeroext i1 @_ZNK4ardb4Data8IsStringEv(ptr noundef nonnull align 8 dereferenceable(13) %0)
  br i1 %2, label %3, label %5

3:                                                ; preds = %1
  %4 = tail call noundef ptr @_ZN4ardb4Data12ToMutableStrEv(ptr noundef nonnull align 8 dereferenceable(13) %0)
  br label %5

5:                                                ; preds = %3, %1
  %6 = getelementptr inbounds i8, ptr %0, i64 24
  %7 = tail call noundef zeroext i1 @_ZNK4ardb4Data8IsStringEv(ptr noundef nonnull align 8 dereferenceable(13) %6)
  br i1 %7, label %8, label %10

8:                                                ; preds = %5
  %9 = tail call noundef ptr @_ZN4ardb4Data12ToMutableStrEv(ptr noundef nonnull align 8 dereferenceable(13) %6)
  br label %10

10:                                               ; preds = %8, %5
  %11 = getelementptr inbounds i8, ptr %0, i64 40
  %12 = tail call noundef i64 @_ZNKSt6vectorIN4ardb4DataESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %11) #3
  %.not = icmp eq i64 %12, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %18, %10
  ret void

.lr.ph:                                           ; preds = %10, %18
  %.04 = phi i64 [ %19, %18 ], [ 0, %10 ]
  %13 = tail call noundef nonnull align 8 dereferenceable(13) ptr @_ZNSt6vectorIN4ardb4DataESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %11, i64 noundef %.04) #3
  %14 = tail call noundef zeroext i1 @_ZNK4ardb4Data8IsStringEv(ptr noundef nonnull align 8 dereferenceable(13) %13)
  br i1 %14, label %15, label %18

15:                                               ; preds = %.lr.ph
  %16 = tail call noundef nonnull align 8 dereferenceable(13) ptr @_ZNSt6vectorIN4ardb4DataESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %11, i64 noundef %.04) #3
  %17 = tail call noundef ptr @_ZN4ardb4Data12ToMutableStrEv(ptr noundef nonnull align 8 dereferenceable(13) %16)
  br label %18

18:                                               ; preds = %.lr.ph, %15
  %19 = add nuw i64 %.04, 1
  %20 = tail call noundef i64 @_ZNKSt6vectorIN4ardb4DataESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %11) #3
  %21 = icmp ult i64 %19, %20
  br i1 %21, label %.lr.ph, label %._crit_edge, !llvm.loop !5
}

declare noundef zeroext i1 @_ZNK4ardb4Data8IsStringEv(ptr noundef nonnull align 8 dereferenceable(13)) local_unnamed_addr #2

declare noundef ptr @_ZN4ardb4Data12ToMutableStrEv(ptr noundef nonnull align 8 dereferenceable(13)) local_unnamed_addr #2

attributes #0 = { 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 #1 = { 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 = { "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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


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