; LLVM IR from stan-dev/math :: lib/boost_1.84.0/libs/container/src (monotonic_buffer_resource)

; 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.boost::container::pmr::monotonic_buffer_resource" = type { %"class.boost::container::pmr::memory_resource", %"class.boost::container::pmr::block_slist", ptr, i64, i64, ptr, i64 }
%"class.boost::container::pmr::memory_resource" = type { ptr }
%"class.boost::container::pmr::block_slist" = type { %"class.boost::container::pmr::block_slist_base", ptr }
%"class.boost::container::pmr::block_slist_base" = type { %"struct.boost::container::pmr::slist_node" }
%"struct.boost::container::pmr::slist_node" = type { ptr }

@_ZTVN5boost9container3pmr25monotonic_buffer_resourceE = external dso_local unnamed_addr constant { [7 x ptr] }, align 8

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

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

; Function Attrs: nounwind
declare noundef ptr @_ZN5boost9container3pmr20get_default_resourceEv() #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN5boost9container3pmr11block_slistC2ERNS1_15memory_resourceE(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #0 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) #3

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN5boost9container3pmr25monotonic_buffer_resourceC2EmPNS1_15memory_resourceE(ptr noundef nonnull align 8 dereferenceable(64) %0, i64 noundef %1, ptr noundef %2) unnamed_addr #4 align 2 personality ptr @__gxx_personality_v0 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  %7 = load ptr, ptr %4, align 8
  call void @_ZN5boost9container3pmr15memory_resourceC2Ev(ptr noundef nonnull align 8 dereferenceable(8) %7) #5
  store ptr getelementptr inbounds inrange(-16, 40) ({ [7 x ptr] }, ptr @_ZTVN5boost9container3pmr25monotonic_buffer_resourceE, i32 0, i32 0, i32 2), ptr %7, align 8, !tbaa !11
  %8 = getelementptr inbounds %"class.boost::container::pmr::monotonic_buffer_resource", ptr %7, i32 0, i32 1
  %9 = load ptr, ptr %6, align 8, !tbaa !5
  %10 = icmp ne ptr %9, null
  br i1 %10, label %11, label %13

11:                                               ; preds = %3
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  br label %15

13:                                               ; preds = %3
  %14 = call noundef ptr @_ZN5boost9container3pmr20get_default_resourceEv() #5
  br label %15

15:                                               ; preds = %13, %11
  %16 = phi ptr [ %12, %11 ], [ %14, %13 ]
  invoke void @_ZN5boost9container3pmr11block_slistC2ERNS1_15memory_resourceE(ptr noundef nonnull align 8 dereferenceable(16) %8, ptr noundef nonnull align 8 dereferenceable(8) %16)
          to label %17 unwind label %30

17:                                               ; preds = %15
  %18 = getelementptr inbounds %"class.boost::container::pmr::monotonic_buffer_resource", ptr %7, i32 0, i32 2
  store ptr null, ptr %18, align 8, !tbaa !13
  %19 = getelementptr inbounds %"class.boost::container::pmr::monotonic_buffer_resource", ptr %7, i32 0, i32 3
  store i64 0, ptr %19, align 8, !tbaa !19
  %20 = getelementptr inbounds %"class.boost::container::pmr::monotonic_buffer_resource", ptr %7, i32 0, i32 4
  store i64 16, ptr %20, align 8, !tbaa !20
  %21 = getelementptr inbounds %"class.boost::container::pmr::monotonic_buffer_resource", ptr %7, i32 0, i32 5
  store ptr null, ptr %21, align 8, !tbaa !21
  %22 = getelementptr inbounds %"class.boost::container::pmr::monotonic_buffer_resource", ptr %7, i32 0, i32 6
  store i64 0, ptr %22, align 8, !tbaa !22
  %23 = load i64, ptr %5, align 8, !tbaa !9
  %24 = load i64, ptr %5, align 8, !tbaa !9
  %25 = icmp ne i64 %24, 0
  %26 = xor i1 %25, true
  %27 = zext i1 %26 to i64
  %28 = add i64 %23, %27
  invoke void @_ZN5boost9container3pmr25monotonic_buffer_resource32increase_next_buffer_at_least_toEm(ptr noundef nonnull align 8 dereferenceable(64) %7, i64 noundef %28)
          to label %29 unwind label %30

29:                                               ; preds = %17
  ret void

30:                                               ; preds = %17, %15
  %31 = landingpad { ptr, i32 }
          catch ptr null
  %32 = extractvalue { ptr, i32 } %31, 0
  call void @__clang_call_terminate(ptr %32) #6
  unreachable
}

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 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 "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 = { noinline noreturn nounwind uwtable "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 = { nounwind }
attributes #6 = { noreturn 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, !12, i64 0}
!12 = !{!"vtable pointer", !8, i64 0}
!13 = !{!14, !6, i64 24}
!14 = !{!"_ZTSN5boost9container3pmr25monotonic_buffer_resourceE", !15, i64 0, !16, i64 8, !6, i64 24, !10, i64 32, !10, i64 40, !6, i64 48, !10, i64 56}
!15 = !{!"_ZTSN5boost9container3pmr15memory_resourceE"}
!16 = !{!"_ZTSN5boost9container3pmr11block_slistE", !17, i64 0, !6, i64 8}
!17 = !{!"_ZTSN5boost9container3pmr16block_slist_baseINS1_18block_slist_headerEEE", !18, i64 0}
!18 = !{!"_ZTSN5boost9container3pmr10slist_nodeE", !6, i64 0}
!19 = !{!14, !10, i64 32}
!20 = !{!14, !10, i64 40}
!21 = !{!14, !6, i64 48}
!22 = !{!14, !10, i64 56}


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

@_ZTVN5boost9container3pmr25monotonic_buffer_resourceE = external dso_local unnamed_addr constant { [7 x ptr] }, align 8

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

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

; Function Attrs: nounwind
declare noundef ptr @_ZN5boost9container3pmr20get_default_resourceEv() local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN5boost9container3pmr11block_slistC2ERNS1_15memory_resourceE(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #0 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN5boost9container3pmr25monotonic_buffer_resourceC2EmPNS1_15memory_resourceE(ptr noundef nonnull align 8 dereferenceable(64) %0, i64 noundef %1, ptr noundef %2) unnamed_addr #4 align 2 personality ptr @__gxx_personality_v0 {
  tail call void @_ZN5boost9container3pmr15memory_resourceC2Ev(ptr noundef nonnull align 8 dereferenceable(8) %0) #7
  store ptr getelementptr inbounds inrange(-16, 40) (i8, ptr @_ZTVN5boost9container3pmr25monotonic_buffer_resourceE, i64 16), ptr %0, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %5, label %7

5:                                                ; preds = %3
  %6 = tail call noundef ptr @_ZN5boost9container3pmr20get_default_resourceEv() #7
  br label %7

7:                                                ; preds = %3, %5
  %8 = phi ptr [ %6, %5 ], [ %2, %3 ]
  invoke void @_ZN5boost9container3pmr11block_slistC2ERNS1_15memory_resourceE(ptr noundef nonnull align 8 dereferenceable(16) %4, ptr noundef nonnull align 8 dereferenceable(8) %8)
          to label %9 unwind label %15

9:                                                ; preds = %7
  %10 = getelementptr inbounds i8, ptr %0, i64 24
  %11 = getelementptr inbounds i8, ptr %0, i64 40
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %10, i8 0, i64 16, i1 false)
  store i64 16, ptr %11, align 8, !tbaa !8
  %12 = getelementptr inbounds i8, ptr %0, i64 48
  %13 = tail call i64 @llvm.umax.i64(i64 %1, i64 1)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %12, i8 0, i64 16, i1 false)
  invoke void @_ZN5boost9container3pmr25monotonic_buffer_resource32increase_next_buffer_at_least_toEm(ptr noundef nonnull align 8 dereferenceable(64) %0, i64 noundef %13)
          to label %14 unwind label %15

14:                                               ; preds = %9
  ret void

15:                                               ; preds = %9, %7
  %16 = landingpad { ptr, i32 }
          catch ptr null
  %17 = extractvalue { ptr, i32 } %16, 0
  tail call void @__clang_call_terminate(ptr %17) #8
  unreachable
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umax.i64(i64, i64) #5

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

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 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 "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 = { noinline noreturn nounwind uwtable "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #6 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #7 = { nounwind }
attributes #8 = { noreturn 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 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !16, i64 40}
!9 = !{!"_ZTSN5boost9container3pmr25monotonic_buffer_resourceE", !10, i64 0, !11, i64 8, !14, i64 24, !16, i64 32, !16, i64 40, !14, i64 48, !16, i64 56}
!10 = !{!"_ZTSN5boost9container3pmr15memory_resourceE"}
!11 = !{!"_ZTSN5boost9container3pmr11block_slistE", !12, i64 0, !14, i64 8}
!12 = !{!"_ZTSN5boost9container3pmr16block_slist_baseINS1_18block_slist_headerEEE", !13, i64 0}
!13 = !{!"_ZTSN5boost9container3pmr10slist_nodeE", !14, i64 0}
!14 = !{!"any pointer", !15, i64 0}
!15 = !{!"omnipotent char", !7, i64 0}
!16 = !{!"long", !15, i64 0}


; Effective O3 passes: GlobalOptPass,InstCombinePass,MemCpyOptPass,SROAPass,SimplifyCFGPass,TailCallElimPass