; 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(none)
declare i64 @llvm.expect.i64(i64, i64) #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i64 @_ZNK5boost9container3pmr13pool_resource26pool_next_blocks_per_chunkEm(ptr noundef nonnull align 8 dereferenceable(56) %0, i64 noundef %1) #1 align 2 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  %6 = load ptr, ptr %4, align 8
  %7 = getelementptr inbounds %"class.boost::container::pmr::pool_resource", ptr %6, i32 0, i32 3
  %8 = load ptr, ptr %7, align 8, !tbaa !11
  %9 = icmp ne ptr %8, null
  br i1 %9, label %10, label %15

10:                                               ; preds = %2
  %11 = load i64, ptr %5, align 8, !tbaa !9
  %12 = getelementptr inbounds %"class.boost::container::pmr::pool_resource", ptr %6, i32 0, i32 4
  %13 = load i64, ptr %12, align 8, !tbaa !16
  %14 = icmp ult i64 %11, %13
  br label %15

15:                                               ; preds = %10, %2
  %16 = phi i1 [ false, %2 ], [ %14, %10 ]
  %17 = zext i1 %16 to i64
  %18 = call i64 @llvm.expect.i64(i64 %17, i64 1)
  %19 = icmp ne i64 %18, 0
  br i1 %19, label %20, label %27

20:                                               ; preds = %15
  %21 = getelementptr inbounds %"class.boost::container::pmr::pool_resource", ptr %6, i32 0, i32 3
  %22 = load ptr, ptr %21, align 8, !tbaa !11
  %23 = load i64, ptr %5, align 8, !tbaa !9
  %24 = getelementptr inbounds %"class.boost::container::pmr::pool_data_t", ptr %22, i64 %23
  %25 = getelementptr inbounds %"class.boost::container::pmr::pool_data_t", ptr %24, i32 0, i32 2
  %26 = load i64, ptr %25, align 8, !tbaa !17
  store i64 %26, ptr %3, align 8
  br label %28

27:                                               ; preds = %15
  store i64 1, ptr %3, align 8
  br label %28

28:                                               ; preds = %27, %20
  %29 = load i64, ptr %3, align 8
  ret i64 %29
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(none) }
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" }

!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 40}
!12 = !{!"_ZTSN5boost9container3pmr13pool_resourceE", !13, i64 0, !6, i64 16, !14, i64 24, !6, i64 40, !10, i64 48}
!13 = !{!"_ZTSN5boost9container3pmr12pool_optionsE", !10, i64 0, !10, i64 8}
!14 = !{!"_ZTSN5boost9container3pmr15block_list_baseINS1_17block_list_headerEEE", !15, i64 0}
!15 = !{!"_ZTSN5boost9container3pmr9list_nodeE", !6, i64 0, !6, i64 8}
!16 = !{!12, !10, i64 48}
!17 = !{!18, !10, i64 16}
!18 = !{!"_ZTSN5boost9container3pmr11pool_data_tE", !19, i64 0, !20, i64 8, !10, i64 16}
!19 = !{!"_ZTSN5boost9container3pmr16block_slist_baseINS1_18block_slist_headerEEE", !20, i64 0}
!20 = !{!"_ZTSN5boost9container3pmr10slist_nodeE", !6, 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"

%"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 nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local noundef i64 @_ZNK5boost9container3pmr13pool_resource26pool_next_blocks_per_chunkEm(ptr nocapture noundef nonnull readonly align 8 dereferenceable(56) %0, i64 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 40
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %.not = icmp ne ptr %4, null
  %5 = getelementptr inbounds i8, ptr %0, i64 48
  %6 = load i64, ptr %5, align 8
  %7 = icmp ugt i64 %6, %1
  %8 = select i1 %.not, i1 %7, i1 false
  br i1 %8, label %9, label %12, !prof !14

9:                                                ; preds = %2
  %10 = getelementptr inbounds %"class.boost::container::pmr::pool_data_t", ptr %4, i64 %1, i32 2
  %11 = load i64, ptr %10, align 8, !tbaa !15
  br label %12

12:                                               ; preds = %2, %9
  %.0 = phi i64 [ %11, %9 ], [ 1, %2 ]
  ret i64 %.0
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) 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" }

!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 40}
!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 = !{!"branch_weights", !"expected", i32 2000, i32 1}
!15 = !{!16, !8, i64 16}
!16 = !{!"_ZTSN5boost9container3pmr11pool_data_tE", !17, i64 0, !18, i64 8, !8, i64 16}
!17 = !{!"_ZTSN5boost9container3pmr16block_slist_baseINS1_18block_slist_headerEEE", !18, i64 0}
!18 = !{!"_ZTSN5boost9container3pmr10slist_nodeE", !11, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,LowerExpectIntrinsicPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass