; LLVM IR from stan-dev/math :: lib/boost_1.84.0/libs/container/src (pool_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::pool_resource" = type { %"struct.boost::container::pmr::pool_options", ptr, %"class.boost::container::pmr::block_list_base", ptr, i64 }
%"struct.boost::container::pmr::pool_options" = type { i64, i64 }
%"class.boost::container::pmr::block_list_base" = type { %"struct.boost::container::pmr::list_node" }
%"struct.boost::container::pmr::list_node" = type { ptr, ptr }
%"class.boost::container::pmr::pool_data_t" = type { %"class.boost::container::pmr::block_slist_base", %"struct.boost::container::pmr::slist_node", i64 }
%"class.boost::container::pmr::block_slist_base" = type { %"struct.boost::container::pmr::slist_node" }
%"struct.boost::container::pmr::slist_node" = type { 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 uwtable
define dso_local void @_ZN5boost9container3pmr13pool_resource7releaseEv(ptr noundef nonnull align 8 dereferenceable(56) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %5 = load ptr, ptr %2, align 8
  %6 = getelementptr inbounds %"class.boost::container::pmr::pool_resource", ptr %5, i32 0, i32 2
  %7 = getelementptr inbounds %"class.boost::container::pmr::pool_resource", ptr %5, i32 0, i32 1
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  call void @_ZN5boost9container3pmr15block_list_baseINS1_17block_list_headerEE7releaseERNS1_15memory_resourceE(ptr noundef nonnull align 8 dereferenceable(16) %6, ptr noundef nonnull align 8 dereferenceable(8) %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  store i64 0, ptr %3, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %9 = getelementptr inbounds %"class.boost::container::pmr::pool_resource", ptr %5, i32 0, i32 4
  %10 = load i64, ptr %9, align 8, !tbaa !16
  store i64 %10, ptr %4, align 8, !tbaa !15
  br label %11

11:                                               ; preds = %23, %1
  %12 = load i64, ptr %3, align 8, !tbaa !15
  %13 = load i64, ptr %4, align 8, !tbaa !15
  %14 = icmp ne i64 %12, %13
  br i1 %14, label %16, label %15

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

16:                                               ; preds = %11
  %17 = getelementptr inbounds %"class.boost::container::pmr::pool_resource", ptr %5, i32 0, i32 3
  %18 = load ptr, ptr %17, align 8, !tbaa !17
  %19 = load i64, ptr %3, align 8, !tbaa !15
  %20 = getelementptr inbounds %"class.boost::container::pmr::pool_data_t", ptr %18, i64 %19
  %21 = getelementptr inbounds %"class.boost::container::pmr::pool_resource", ptr %5, i32 0, i32 1
  %22 = load ptr, ptr %21, align 8, !tbaa !9
  call void @_ZN5boost9container3pmr11pool_data_t7releaseERNS1_15memory_resourceE(ptr noundef nonnull align 8 dereferenceable(24) %20, ptr noundef nonnull align 8 dereferenceable(8) %22)
  br label %23

23:                                               ; preds = %16
  %24 = load i64, ptr %3, align 8, !tbaa !15
  %25 = add i64 %24, 1
  store i64 %25, ptr %3, align 8, !tbaa !15
  br label %11, !llvm.loop !18

26:                                               ; preds = %15
  ret void
}

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

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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, !6, i64 16}
!10 = !{!"_ZTSN5boost9container3pmr13pool_resourceE", !11, i64 0, !6, i64 16, !13, i64 24, !6, i64 40, !12, i64 48}
!11 = !{!"_ZTSN5boost9container3pmr12pool_optionsE", !12, i64 0, !12, i64 8}
!12 = !{!"long", !7, i64 0}
!13 = !{!"_ZTSN5boost9container3pmr15block_list_baseINS1_17block_list_headerEEE", !14, i64 0}
!14 = !{!"_ZTSN5boost9container3pmr9list_nodeE", !6, i64 0, !6, i64 8}
!15 = !{!12, !12, i64 0}
!16 = !{!10, !12, i64 48}
!17 = !{!10, !6, i64 40}
!18 = distinct !{!18, !19}
!19 = !{!"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"

%"class.boost::container::pmr::pool_data_t" = type { %"class.boost::container::pmr::block_slist_base", %"struct.boost::container::pmr::slist_node", i64 }
%"class.boost::container::pmr::block_slist_base" = type { %"struct.boost::container::pmr::slist_node" }
%"struct.boost::container::pmr::slist_node" = type { ptr }

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN5boost9container3pmr13pool_resource7releaseEv(ptr noundef nonnull align 8 dereferenceable(56) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 24
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  tail call void @_ZN5boost9container3pmr15block_list_baseINS1_17block_list_headerEE7releaseERNS1_15memory_resourceE(ptr noundef nonnull align 8 dereferenceable(16) %2, ptr noundef nonnull align 8 dereferenceable(8) %4) #2
  %5 = getelementptr inbounds i8, ptr %0, i64 48
  %6 = load i64, ptr %5, align 8, !tbaa !14
  %.not4 = icmp eq i64 %6, 0
  br i1 %.not4, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %7 = getelementptr inbounds i8, ptr %0, i64 40
  br label %8

._crit_edge:                                      ; preds = %8, %1
  ret void

8:                                                ; preds = %.lr.ph, %8
  %.05 = phi i64 [ 0, %.lr.ph ], [ %12, %8 ]
  %9 = load ptr, ptr %7, align 8, !tbaa !15
  %10 = getelementptr inbounds %"class.boost::container::pmr::pool_data_t", ptr %9, i64 %.05
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  tail call void @_ZN5boost9container3pmr11pool_data_t7releaseERNS1_15memory_resourceE(ptr noundef nonnull align 8 dereferenceable(24) %10, ptr noundef nonnull align 8 dereferenceable(8) %11)
  %12 = add nuw i64 %.05, 1
  %.not = icmp eq i64 %12, %6
  br i1 %.not, label %._crit_edge, label %8, !llvm.loop !16
}

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN5boost9container3pmr11pool_data_t7releaseERNS1_15memory_resourceE(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #0 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, !11, i64 16}
!6 = !{!"_ZTSN5boost9container3pmr13pool_resourceE", !7, i64 0, !11, i64 16, !12, i64 24, !11, i64 40, !8, i64 48}
!7 = !{!"_ZTSN5boost9container3pmr12pool_optionsE", !8, i64 0, !8, i64 8}
!8 = !{!"long", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"any pointer", !9, i64 0}
!12 = !{!"_ZTSN5boost9container3pmr15block_list_baseINS1_17block_list_headerEEE", !13, i64 0}
!13 = !{!"_ZTSN5boost9container3pmr9list_nodeE", !11, i64 0, !11, i64 8}
!14 = !{!6, !8, i64 48}
!15 = !{!6, !11, i64 40}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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