; LLVM IR from pixelsdb/mini-pixels :: pixels-common/lib/physical/allocator (BufferPoolAllocator)

; 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.std::shared_ptr" = type { %"class.std::__shared_ptr" }
%"class.std::__shared_ptr" = type { ptr, %"class.std::__shared_count" }
%"class.std::__shared_count" = type { ptr }
%class.BufferPoolAllocator = type { %class.Allocator, i64, %"class.std::shared_ptr" }
%class.Allocator = type { ptr }

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

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

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) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN19BufferPoolAllocator8allocateEi(ptr dead_on_unwind noalias writable sret(%"class.std::shared_ptr") align 8 %0, ptr noundef nonnull align 8 dereferenceable(32) %1, i32 noundef %2) unnamed_addr #2 align 2 personality ptr @__gxx_personality_v0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i1, align 1
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %4, align 8
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  %13 = load ptr, ptr %5, align 8
  store i1 false, ptr %7, align 1
  %14 = getelementptr inbounds %class.BufferPoolAllocator, ptr %13, i32 0, i32 2
  %15 = call noundef nonnull align 8 dereferenceable(62) ptr @_ZNKSt19__shared_ptr_accessI10ByteBufferLN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEdeEv(ptr noundef nonnull align 1 dereferenceable(1) %14) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %16 = getelementptr inbounds %class.BufferPoolAllocator, ptr %13, i32 0, i32 2
  %17 = call noundef ptr @_ZNKSt19__shared_ptr_accessI10ByteBufferLN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1) %16) #4
  %18 = call noundef i32 @_ZN10ByteBuffer10getReadPosEv(ptr noundef nonnull align 8 dereferenceable(62) %17)
  store i32 %18, ptr %8, align 4, !tbaa !9
  call void @_ZSt11make_sharedI10ByteBufferJRS0_jRiEESt10shared_ptrINSt9enable_ifIXntsr8is_arrayIT_EE5valueES5_E4typeEEDpOT0_(ptr dead_on_unwind writable sret(%"class.std::shared_ptr") align 8 %0, ptr noundef nonnull align 8 dereferenceable(62) %15, ptr noundef nonnull align 4 dereferenceable(4) %8, ptr noundef nonnull align 4 dereferenceable(4) %6)
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %19 = load i32, ptr %6, align 4, !tbaa !9
  %20 = srem i32 %19, 4096
  store i32 %20, ptr %10, align 4, !tbaa !9
  %21 = load i32, ptr %10, align 4, !tbaa !9
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %23, label %28

23:                                               ; preds = %3
  %24 = load i32, ptr %6, align 4, !tbaa !9
  %25 = add nsw i32 %24, 4096
  %26 = load i32, ptr %10, align 4, !tbaa !9
  %27 = sub nsw i32 %25, %26
  store i32 %27, ptr %9, align 4, !tbaa !9
  br label %30

28:                                               ; preds = %3
  %29 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %29, ptr %9, align 4, !tbaa !9
  br label %30

30:                                               ; preds = %28, %23
  %31 = getelementptr inbounds %class.BufferPoolAllocator, ptr %13, i32 0, i32 2
  %32 = call noundef ptr @_ZNKSt19__shared_ptr_accessI10ByteBufferLN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1) %31) #4
  %33 = getelementptr inbounds %class.BufferPoolAllocator, ptr %13, i32 0, i32 2
  %34 = call noundef ptr @_ZNKSt19__shared_ptr_accessI10ByteBufferLN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1) %33) #4
  %35 = invoke noundef i32 @_ZN10ByteBuffer10getReadPosEv(ptr noundef nonnull align 8 dereferenceable(62) %34)
          to label %36 unwind label %41

36:                                               ; preds = %30
  %37 = load i32, ptr %9, align 4, !tbaa !9
  %38 = add i32 %35, %37
  invoke void @_ZN10ByteBuffer10setReadPosEj(ptr noundef nonnull align 8 dereferenceable(62) %32, i32 noundef %38)
          to label %39 unwind label %41

39:                                               ; preds = %36
  store i1 true, ptr %7, align 1
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  %40 = load i1, ptr %7, align 1
  br i1 %40, label %46, label %45

41:                                               ; preds = %36, %30
  %42 = landingpad { ptr, i32 }
          cleanup
  %43 = extractvalue { ptr, i32 } %42, 0
  store ptr %43, ptr %11, align 8
  %44 = extractvalue { ptr, i32 } %42, 1
  store i32 %44, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @_ZNSt12__shared_ptrI10ByteBufferLN9__gnu_cxx12_Lock_policyE2EED2Ev(ptr noundef nonnull align 8 dereferenceable(16) %0) #4
  br label %47

45:                                               ; preds = %39
  call void @_ZNSt12__shared_ptrI10ByteBufferLN9__gnu_cxx12_Lock_policyE2EED2Ev(ptr noundef nonnull align 8 dereferenceable(16) %0) #4
  br label %46

46:                                               ; preds = %45, %39
  ret void

47:                                               ; preds = %41
  %48 = load ptr, ptr %11, align 8
  %49 = load i32, ptr %12, align 4
  %50 = insertvalue { ptr, i32 } poison, ptr %48, 0
  %51 = insertvalue { ptr, i32 } %50, i32 %49, 1
  resume { ptr, i32 } %51
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt11make_sharedI10ByteBufferJRS0_jRiEESt10shared_ptrINSt9enable_ifIXntsr8is_arrayIT_EE5valueES5_E4typeEEDpOT0_(ptr dead_on_unwind noalias writable sret(%"class.std::shared_ptr") align 8, ptr noundef nonnull align 8 dereferenceable(62), ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #3

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN10ByteBuffer10getReadPosEv(ptr noundef nonnull align 8 dereferenceable(62)) #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN10ByteBuffer10setReadPosEj(ptr noundef nonnull align 8 dereferenceable(62), i32 noundef) #0 align 2

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { inlinehint 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 = { 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 = !{!"int", !7, 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.std::shared_ptr" = type { %"class.std::__shared_ptr" }
%"class.std::__shared_ptr" = type { ptr, %"class.std::__shared_count" }
%"class.std::__shared_count" = type { ptr }

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

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

declare i32 @__gxx_personality_v0(...)

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN19BufferPoolAllocator8allocateEi(ptr dead_on_unwind noalias writable sret(%"class.std::shared_ptr") align 8 %0, ptr noundef nonnull align 8 dereferenceable(32) %1, i32 noundef %2) unnamed_addr #2 align 2 personality ptr @__gxx_personality_v0 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 %2, ptr %4, align 4, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %1, i64 16
  %7 = tail call noundef nonnull align 8 dereferenceable(62) ptr @_ZNKSt19__shared_ptr_accessI10ByteBufferLN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEdeEv(ptr noundef nonnull align 1 dereferenceable(1) %6) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #4
  %8 = tail call noundef ptr @_ZNKSt19__shared_ptr_accessI10ByteBufferLN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1) %6) #4
  %9 = tail call noundef i32 @_ZN10ByteBuffer10getReadPosEv(ptr noundef nonnull align 8 dereferenceable(62) %8)
  store i32 %9, ptr %5, align 4, !tbaa !5
  call void @_ZSt11make_sharedI10ByteBufferJRS0_jRiEESt10shared_ptrINSt9enable_ifIXntsr8is_arrayIT_EE5valueES5_E4typeEEDpOT0_(ptr dead_on_unwind writable sret(%"class.std::shared_ptr") align 8 %0, ptr noundef nonnull align 8 dereferenceable(62) %7, ptr noundef nonnull align 4 dereferenceable(4) %5, ptr noundef nonnull align 4 dereferenceable(4) %4)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #4
  %10 = load i32, ptr %4, align 4, !tbaa !5
  %11 = srem i32 %10, 4096
  %.not = icmp eq i32 %11, 0
  %12 = add nsw i32 %10, 4096
  %13 = sub i32 %12, %11
  %.0 = select i1 %.not, i32 %10, i32 %13
  %14 = call noundef ptr @_ZNKSt19__shared_ptr_accessI10ByteBufferLN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1) %6) #4
  %15 = call noundef ptr @_ZNKSt19__shared_ptr_accessI10ByteBufferLN9__gnu_cxx12_Lock_policyE2ELb0ELb0EEptEv(ptr noundef nonnull align 1 dereferenceable(1) %6) #4
  %16 = call noundef i32 @_ZN10ByteBuffer10getReadPosEv(ptr noundef nonnull align 8 dereferenceable(62) %15)
  %17 = add i32 %16, %.0
  call void @_ZN10ByteBuffer10setReadPosEj(ptr noundef nonnull align 8 dereferenceable(62) %14, i32 noundef %17)
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt11make_sharedI10ByteBufferJRS0_jRiEESt10shared_ptrINSt9enable_ifIXntsr8is_arrayIT_EE5valueES5_E4typeEEDpOT0_(ptr dead_on_unwind noalias writable sret(%"class.std::shared_ptr") align 8, ptr noundef nonnull align 8 dereferenceable(62), ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #3

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN10ByteBuffer10getReadPosEv(ptr noundef nonnull align 8 dereferenceable(62)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN10ByteBuffer10setReadPosEj(ptr noundef nonnull align 8 dereferenceable(62), i32 noundef) local_unnamed_addr #0 align 2

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { inlinehint 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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass