; LLVM IR from yinqiwen/ardb :: src/types.ll (ZN4ardb4Data18ReserveStringSpaceEm)

; 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::Data" = type <{ i64, i32, i8, [3 x i8] }>

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4ardb4Data5ClearEv(ptr noundef nonnull align 8 dereferenceable(13)) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN4ardb4Data18ReserveStringSpaceEm(ptr noundef nonnull align 8 dereferenceable(13) %0, i64 noundef %1) #2 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  %6 = load ptr, ptr %3, align 8
  %7 = call noundef ptr @_ZN4ardb4Data12ToMutableStrEv(ptr noundef nonnull align 8 dereferenceable(13) %6)
  %8 = call noundef i32 @_ZNK4ardb4Data12StringLengthEv(ptr noundef nonnull align 8 dereferenceable(13) %6)
  %9 = zext i32 %8 to i64
  %10 = load i64, ptr %4, align 8, !tbaa !9
  %11 = icmp ult i64 %9, %10
  br i1 %11, label %12, label %37

12:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #6
  %13 = load i64, ptr %4, align 8, !tbaa !9
  %14 = call noalias ptr @malloc(i64 noundef %13) #7
  store ptr %14, ptr %5, align 8, !tbaa !5
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = call noundef i32 @_ZNK4ardb4Data12StringLengthEv(ptr noundef nonnull align 8 dereferenceable(13) %6)
  %17 = zext i32 %16 to i64
  %18 = getelementptr inbounds i8, ptr %15, i64 %17
  %19 = load i64, ptr %4, align 8, !tbaa !9
  %20 = call noundef i32 @_ZNK4ardb4Data12StringLengthEv(ptr noundef nonnull align 8 dereferenceable(13) %6)
  %21 = zext i32 %20 to i64
  %22 = sub i64 %19, %21
  call void @llvm.memset.p0.i64(ptr align 1 %18, i8 0, i64 %22, i1 false)
  %23 = call noundef zeroext i1 @_ZNK4ardb4Data8IsStringEv(ptr noundef nonnull align 8 dereferenceable(13) %6)
  br i1 %23, label %24, label %29

24:                                               ; preds = %12
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = call noundef ptr @_ZNK4ardb4Data4CStrEv(ptr noundef nonnull align 8 dereferenceable(13) %6)
  %27 = call noundef i32 @_ZNK4ardb4Data12StringLengthEv(ptr noundef nonnull align 8 dereferenceable(13) %6)
  %28 = zext i32 %27 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %25, ptr align 1 %26, i64 %28, i1 false)
  call void @_ZN4ardb4Data5ClearEv(ptr noundef nonnull align 8 dereferenceable(13) %6)
  br label %29

29:                                               ; preds = %24, %12
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = ptrtoint ptr %30 to i64
  %32 = getelementptr inbounds %"struct.ardb::Data", ptr %6, i32 0, i32 0
  store i64 %31, ptr %32, align 8, !tbaa !11
  %33 = getelementptr inbounds %"struct.ardb::Data", ptr %6, i32 0, i32 2
  store i8 4, ptr %33, align 4, !tbaa !14
  %34 = load i64, ptr %4, align 8, !tbaa !9
  %35 = trunc i64 %34 to i32
  %36 = getelementptr inbounds %"struct.ardb::Data", ptr %6, i32 0, i32 1
  store i32 %35, ptr %36, align 8, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  br label %37

37:                                               ; preds = %29, %2
  %38 = getelementptr inbounds %"struct.ardb::Data", ptr %6, i32 0, i32 0
  %39 = load i64, ptr %38, align 8, !tbaa !11
  %40 = inttoptr i64 %39 to ptr
  ret ptr %40
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN4ardb4Data12ToMutableStrEv(ptr noundef nonnull align 8 dereferenceable(13)) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZNK4ardb4Data12StringLengthEv(ptr noundef nonnull align 8 dereferenceable(13)) #2 align 2

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #4

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #5

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK4ardb4Data8IsStringEv(ptr noundef nonnull align 8 dereferenceable(13)) #1 align 2

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

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

attributes #0 = { nocallback nofree 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nounwind allocsize(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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { nounwind }
attributes #7 = { nounwind allocsize(0) }

!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, !10, i64 0}
!12 = !{!"_ZTSN4ardb4DataE", !10, i64 0, !13, i64 8, !7, i64 12}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !7, i64 12}
!15 = !{!12, !13, i64 8}


; 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 nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4ardb4Data5ClearEv(ptr noundef nonnull align 8 dereferenceable(13)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN4ardb4Data18ReserveStringSpaceEm(ptr noundef nonnull align 8 dereferenceable(13) %0, i64 noundef %1) local_unnamed_addr #2 align 2 {
  %3 = tail call noundef ptr @_ZN4ardb4Data12ToMutableStrEv(ptr noundef nonnull align 8 dereferenceable(13) %0)
  %4 = tail call noundef i32 @_ZNK4ardb4Data12StringLengthEv(ptr noundef nonnull align 8 dereferenceable(13) %0)
  %5 = zext i32 %4 to i64
  %6 = icmp ult i64 %5, %1
  br i1 %6, label %8, label %._crit_edge

._crit_edge:                                      ; preds = %2
  %.pre = load i64, ptr %0, align 8, !tbaa !5
  %7 = inttoptr i64 %.pre to ptr
  br label %26

8:                                                ; preds = %2
  %9 = tail call noalias ptr @malloc(i64 noundef %1) #5
  %10 = tail call noundef i32 @_ZNK4ardb4Data12StringLengthEv(ptr noundef nonnull align 8 dereferenceable(13) %0)
  %11 = zext i32 %10 to i64
  %12 = getelementptr inbounds i8, ptr %9, i64 %11
  %13 = tail call noundef i32 @_ZNK4ardb4Data12StringLengthEv(ptr noundef nonnull align 8 dereferenceable(13) %0)
  %14 = zext i32 %13 to i64
  %15 = sub i64 %1, %14
  tail call void @llvm.memset.p0.i64(ptr align 1 %12, i8 0, i64 %15, i1 false)
  %16 = tail call noundef zeroext i1 @_ZNK4ardb4Data8IsStringEv(ptr noundef nonnull align 8 dereferenceable(13) %0)
  br i1 %16, label %17, label %21

17:                                               ; preds = %8
  %18 = tail call noundef ptr @_ZNK4ardb4Data4CStrEv(ptr noundef nonnull align 8 dereferenceable(13) %0)
  %19 = tail call noundef i32 @_ZNK4ardb4Data12StringLengthEv(ptr noundef nonnull align 8 dereferenceable(13) %0)
  %20 = zext i32 %19 to i64
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %9, ptr align 1 %18, i64 %20, i1 false)
  tail call void @_ZN4ardb4Data5ClearEv(ptr noundef nonnull align 8 dereferenceable(13) %0)
  br label %21

21:                                               ; preds = %17, %8
  %22 = ptrtoint ptr %9 to i64
  store i64 %22, ptr %0, align 8, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %0, i64 12
  store i8 4, ptr %23, align 4, !tbaa !11
  %24 = trunc i64 %1 to i32
  %25 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 %24, ptr %25, align 8, !tbaa !12
  br label %26

26:                                               ; preds = %._crit_edge, %21
  %27 = phi ptr [ %7, %._crit_edge ], [ %9, %21 ]
  ret ptr %27
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN4ardb4Data12ToMutableStrEv(ptr noundef nonnull align 8 dereferenceable(13)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZNK4ardb4Data12StringLengthEv(ptr noundef nonnull align 8 dereferenceable(13)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK4ardb4Data8IsStringEv(ptr noundef nonnull align 8 dereferenceable(13)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK4ardb4Data4CStrEv(ptr noundef nonnull align 8 dereferenceable(13)) local_unnamed_addr #1 align 2

attributes #0 = { mustprogress nocallback nofree 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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { nounwind allocsize(0) }

!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 = !{!"_ZTSN4ardb4DataE", !7, i64 0, !10, i64 8, !8, i64 12}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !8, i64 12}
!12 = !{!6, !10, i64 8}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,TailCallElimPass