; LLVM IR from facebook/redex :: libredex/RedexContext.ll (ZN12RedexContext23ConcurrentStringStorage9Container8allocateEm)

; 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.RedexContext::ConcurrentStringStorage::Container" = type { i64, ptr }
%"struct.RedexContext::ConcurrentStringStorage::Container::Buffer" = type { i64, i64, %"class.std::unique_ptr", ptr }
%"class.std::unique_ptr" = type { %"struct.std::__uniq_ptr_data" }
%"struct.std::__uniq_ptr_data" = type { %"class.std::__uniq_ptr_impl" }
%"class.std::__uniq_ptr_impl" = type { %"class.std::tuple" }
%"class.std::tuple" = type { %"struct.std::_Tuple_impl" }
%"struct.std::_Tuple_impl" = type { %"struct.std::_Head_base.171" }
%"struct.std::_Head_base.171" = type { ptr }

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

declare i32 @__gxx_personality_v0(...)

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

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) #1

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN12RedexContext23ConcurrentStringStorage9Container8allocateEm(ptr noundef nonnull align 8 dereferenceable(16) %0, i64 noundef %1) #3 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  %8 = load ptr, ptr %3, align 8
  %9 = getelementptr inbounds %"struct.RedexContext::ConcurrentStringStorage::Container", ptr %8, i32 0, i32 1
  %10 = load ptr, ptr %9, align 8, !tbaa !11
  %11 = icmp eq ptr %10, null
  br i1 %11, label %24, label %12

12:                                               ; preds = %2
  %13 = getelementptr inbounds %"struct.RedexContext::ConcurrentStringStorage::Container", ptr %8, i32 0, i32 1
  %14 = load ptr, ptr %13, align 8, !tbaa !11
  %15 = getelementptr inbounds %"struct.RedexContext::ConcurrentStringStorage::Container::Buffer", ptr %14, i32 0, i32 1
  %16 = load i64, ptr %15, align 8, !tbaa !13
  %17 = load i64, ptr %4, align 8, !tbaa !9
  %18 = add i64 %16, %17
  %19 = getelementptr inbounds %"struct.RedexContext::ConcurrentStringStorage::Container", ptr %8, i32 0, i32 1
  %20 = load ptr, ptr %19, align 8, !tbaa !11
  %21 = getelementptr inbounds %"struct.RedexContext::ConcurrentStringStorage::Container::Buffer", ptr %20, i32 0, i32 0
  %22 = load i64, ptr %21, align 8, !tbaa !21
  %23 = icmp ugt i64 %18, %22
  br i1 %23, label %24, label %44

24:                                               ; preds = %12, %2
  %25 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 32) #5
  %26 = getelementptr inbounds %"struct.RedexContext::ConcurrentStringStorage::Container", ptr %8, i32 0, i32 0
  %27 = load i64, ptr %26, align 8, !tbaa !22
  %28 = icmp eq i64 %27, 0
  br i1 %28, label %29, label %31

29:                                               ; preds = %24
  %30 = load i64, ptr %4, align 8, !tbaa !9
  br label %34

31:                                               ; preds = %24
  %32 = getelementptr inbounds %"struct.RedexContext::ConcurrentStringStorage::Container", ptr %8, i32 0, i32 0
  %33 = load i64, ptr %32, align 8, !tbaa !22
  br label %34

34:                                               ; preds = %31, %29
  %35 = phi i64 [ %30, %29 ], [ %33, %31 ]
  %36 = getelementptr inbounds %"struct.RedexContext::ConcurrentStringStorage::Container", ptr %8, i32 0, i32 1
  %37 = load ptr, ptr %36, align 8, !tbaa !11
  invoke void @_ZN12RedexContext23ConcurrentStringStorage9Container6BufferC2EmPS2_(ptr noundef nonnull align 8 dereferenceable(32) %25, i64 noundef %35, ptr noundef %37)
          to label %38 unwind label %40

38:                                               ; preds = %34
  %39 = getelementptr inbounds %"struct.RedexContext::ConcurrentStringStorage::Container", ptr %8, i32 0, i32 1
  store ptr %25, ptr %39, align 8, !tbaa !11
  br label %44

40:                                               ; preds = %34
  %41 = landingpad { ptr, i32 }
          cleanup
  %42 = extractvalue { ptr, i32 } %41, 0
  store ptr %42, ptr %5, align 8
  %43 = extractvalue { ptr, i32 } %41, 1
  store i32 %43, ptr %6, align 4
  call void @_ZdlPvm(ptr noundef %25, i64 noundef 32) #6
  br label %61

44:                                               ; preds = %38, %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #7
  %45 = getelementptr inbounds %"struct.RedexContext::ConcurrentStringStorage::Container", ptr %8, i32 0, i32 1
  %46 = load ptr, ptr %45, align 8, !tbaa !11
  %47 = getelementptr inbounds %"struct.RedexContext::ConcurrentStringStorage::Container::Buffer", ptr %46, i32 0, i32 2
  %48 = call noundef ptr @_ZNKSt10unique_ptrIA_cSt14default_deleteIS0_EE3getEv(ptr noundef nonnull align 8 dereferenceable(8) %47) #7
  %49 = getelementptr inbounds %"struct.RedexContext::ConcurrentStringStorage::Container", ptr %8, i32 0, i32 1
  %50 = load ptr, ptr %49, align 8, !tbaa !11
  %51 = getelementptr inbounds %"struct.RedexContext::ConcurrentStringStorage::Container::Buffer", ptr %50, i32 0, i32 1
  %52 = load i64, ptr %51, align 8, !tbaa !13
  %53 = getelementptr inbounds i8, ptr %48, i64 %52
  store ptr %53, ptr %7, align 8, !tbaa !5
  %54 = load i64, ptr %4, align 8, !tbaa !9
  %55 = getelementptr inbounds %"struct.RedexContext::ConcurrentStringStorage::Container", ptr %8, i32 0, i32 1
  %56 = load ptr, ptr %55, align 8, !tbaa !11
  %57 = getelementptr inbounds %"struct.RedexContext::ConcurrentStringStorage::Container::Buffer", ptr %56, i32 0, i32 1
  %58 = load i64, ptr %57, align 8, !tbaa !13
  %59 = add i64 %58, %54
  store i64 %59, ptr %57, align 8, !tbaa !13
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #7
  ret ptr %60

61:                                               ; preds = %40
  %62 = load ptr, ptr %5, align 8
  %63 = load i32, ptr %6, align 4
  %64 = insertvalue { ptr, i32 } poison, ptr %62, 0
  %65 = insertvalue { ptr, i32 } %64, i32 %63, 1
  resume { ptr, i32 } %65
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN12RedexContext23ConcurrentStringStorage9Container6BufferC2EmPS2_(ptr noundef nonnull align 8 dereferenceable(32), i64 noundef, ptr noundef) unnamed_addr #3 align 2

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nobuiltin 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 #2 = { nobuiltin nounwind "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 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 = { 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 #5 = { builtin allocsize(0) }
attributes #6 = { builtin nounwind }
attributes #7 = { 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, !6, i64 8}
!12 = !{!"_ZTSN12RedexContext23ConcurrentStringStorage9ContainerE", !10, i64 0, !6, i64 8}
!13 = !{!14, !10, i64 8}
!14 = !{!"_ZTSN12RedexContext23ConcurrentStringStorage9Container6BufferE", !10, i64 0, !10, i64 8, !15, i64 16, !6, i64 24}
!15 = !{!"_ZTSSt10unique_ptrIA_cSt14default_deleteIS0_EE", !16, i64 0}
!16 = !{!"_ZTSSt15__uniq_ptr_dataIcSt14default_deleteIA_cELb1ELb1EE", !17, i64 0}
!17 = !{!"_ZTSSt15__uniq_ptr_implIcSt14default_deleteIA_cEE", !18, i64 0}
!18 = !{!"_ZTSSt5tupleIJPcSt14default_deleteIA_cEEE", !19, i64 0}
!19 = !{!"_ZTSSt11_Tuple_implILm0EJPcSt14default_deleteIA_cEEE", !20, i64 0}
!20 = !{!"_ZTSSt10_Head_baseILm0EPcLb0EE", !6, i64 0}
!21 = !{!14, !10, i64 0}
!22 = !{!12, !10, i64 0}


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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) local_unnamed_addr #0

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN12RedexContext23ConcurrentStringStorage9Container8allocateEm(ptr nocapture noundef nonnull align 8 dereferenceable(16) %0, i64 noundef %1) local_unnamed_addr #2 align 2 personality ptr @__gxx_personality_v0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = icmp eq ptr %4, null
  br i1 %5, label %12, label %6

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %4, i64 8
  %8 = load i64, ptr %7, align 8, !tbaa !11
  %9 = add i64 %8, %1
  %10 = load i64, ptr %4, align 8, !tbaa !19
  %11 = icmp ugt i64 %9, %10
  br i1 %11, label %12, label %19

12:                                               ; preds = %6, %2
  %13 = tail call noalias noundef nonnull dereferenceable(32) ptr @_Znwm(i64 noundef 32) #4
  %14 = load i64, ptr %0, align 8, !tbaa !20
  %15 = icmp eq i64 %14, 0
  %. = select i1 %15, i64 %1, i64 %14
  invoke void @_ZN12RedexContext23ConcurrentStringStorage9Container6BufferC2EmPS2_(ptr noundef nonnull align 8 dereferenceable(32) %13, i64 noundef %., ptr noundef %4)
          to label %16 unwind label %17

16:                                               ; preds = %12
  store ptr %13, ptr %3, align 8, !tbaa !5
  br label %19

17:                                               ; preds = %12
  %18 = landingpad { ptr, i32 }
          cleanup
  tail call void @_ZdlPvm(ptr noundef nonnull %13, i64 noundef 32) #5
  resume { ptr, i32 } %18

19:                                               ; preds = %16, %6
  %20 = phi ptr [ %13, %16 ], [ %4, %6 ]
  %21 = getelementptr inbounds i8, ptr %20, i64 16
  %22 = tail call noundef ptr @_ZNKSt10unique_ptrIA_cSt14default_deleteIS0_EE3getEv(ptr noundef nonnull align 8 dereferenceable(8) %21) #6
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %23, i64 8
  %25 = load i64, ptr %24, align 8, !tbaa !11
  %26 = getelementptr inbounds i8, ptr %22, i64 %25
  %27 = add i64 %25, %1
  store i64 %27, ptr %24, align 8, !tbaa !11
  ret ptr %26
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN12RedexContext23ConcurrentStringStorage9Container6BufferC2EmPS2_(ptr noundef nonnull align 8 dereferenceable(32), i64 noundef, ptr noundef) unnamed_addr #2 align 2

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

attributes #0 = { nobuiltin 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 #1 = { nobuiltin nounwind "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 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 = { builtin allocsize(0) }
attributes #5 = { builtin nounwind }
attributes #6 = { 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, !10, i64 8}
!6 = !{!"_ZTSN12RedexContext23ConcurrentStringStorage9ContainerE", !7, i64 0, !10, i64 8}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!12, !7, i64 8}
!12 = !{!"_ZTSN12RedexContext23ConcurrentStringStorage9Container6BufferE", !7, i64 0, !7, i64 8, !13, i64 16, !10, i64 24}
!13 = !{!"_ZTSSt10unique_ptrIA_cSt14default_deleteIS0_EE", !14, i64 0}
!14 = !{!"_ZTSSt15__uniq_ptr_dataIcSt14default_deleteIA_cELb1ELb1EE", !15, i64 0}
!15 = !{!"_ZTSSt15__uniq_ptr_implIcSt14default_deleteIA_cEE", !16, i64 0}
!16 = !{!"_ZTSSt5tupleIJPcSt14default_deleteIA_cEEE", !17, i64 0}
!17 = !{!"_ZTSSt11_Tuple_implILm0EJPcSt14default_deleteIA_cEEE", !18, i64 0}
!18 = !{!"_ZTSSt10_Head_baseILm0EPcLb0EE", !10, i64 0}
!19 = !{!12, !7, i64 0}
!20 = !{!6, !7, i64 0}


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