; LLVM IR from vczh/herodb :: Kernel/Source/Utility/Buffer.ll (ZN2vl8database13BufferManagerC2Emm)

; 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.vl::database::BufferManager" = type { i64, i64, i64, i64, %"class.vl::SpinLock", i64, %"class.vl::collections::Dictionary" }
%"class.vl::SpinLock" = type { %"class.vl::Object", i64 }
%"class.vl::Object" = type { ptr }
%"class.vl::collections::Dictionary" = type { %"class.vl::Object", %"class.vl::collections::SortedList", %"class.vl::collections::List", %"class.vl::collections::IEnumerable.6" }
%"class.vl::collections::SortedList" = type { %"class.vl::collections::ListBase.base", %"class.vl::collections::IEnumerable" }
%"class.vl::collections::ListBase.base" = type <{ %"class.vl::collections::ArrayBase.base", i64, i8 }>
%"class.vl::collections::ArrayBase.base" = type { %"class.vl::collections::ListStore", ptr, i64 }
%"class.vl::collections::ListStore" = type { %"class.vl::Object" }
%"class.vl::collections::IEnumerable" = type { %"class.vl::Interface" }
%"class.vl::Interface" = type { ptr }
%"class.vl::collections::List" = type { %"class.vl::collections::ListBase.base.5", %"class.vl::collections::IEnumerable.3" }
%"class.vl::collections::ListBase.base.5" = type <{ %"class.vl::collections::ArrayBase.base.4", i64, i8 }>
%"class.vl::collections::ArrayBase.base.4" = type { %"class.vl::collections::ListStore.2", ptr, i64 }
%"class.vl::collections::ListStore.2" = type { %"class.vl::Object" }
%"class.vl::collections::IEnumerable.3" = type { %"class.vl::Interface" }
%"class.vl::collections::IEnumerable.6" = type { %"class.vl::Interface" }

; 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: mustprogress uwtable
define dso_local void @_ZN2vl8database13BufferManagerC2Emm(ptr noundef nonnull align 8 dereferenceable(168) %0, i64 noundef %1, i64 noundef %2) unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  store i64 %2, ptr %6, align 8, !tbaa !9
  %10 = load ptr, ptr %4, align 8
  %11 = getelementptr inbounds %"class.vl::database::BufferManager", ptr %10, i32 0, i32 0
  %12 = load i64, ptr %5, align 8, !tbaa !9
  store i64 %12, ptr %11, align 8, !tbaa !11
  %13 = getelementptr inbounds %"class.vl::database::BufferManager", ptr %10, i32 0, i32 1
  %14 = load i64, ptr %6, align 8, !tbaa !9
  store i64 %14, ptr %13, align 8, !tbaa !25
  %15 = getelementptr inbounds %"class.vl::database::BufferManager", ptr %10, i32 0, i32 2
  store i64 0, ptr %15, align 8, !tbaa !26
  %16 = getelementptr inbounds %"class.vl::database::BufferManager", ptr %10, i32 0, i32 3
  store volatile i64 0, ptr %16, align 8, !tbaa !27
  %17 = getelementptr inbounds %"class.vl::database::BufferManager", ptr %10, i32 0, i32 4
  call void @_ZN2vl8SpinLockC1Ev(ptr noundef nonnull align 8 dereferenceable(16) %17)
  %18 = getelementptr inbounds %"class.vl::database::BufferManager", ptr %10, i32 0, i32 5
  store volatile i64 0, ptr %18, align 8, !tbaa !28
  %19 = getelementptr inbounds %"class.vl::database::BufferManager", ptr %10, i32 0, i32 6
  invoke void @_ZN2vl11collections10DictionaryINS_8database8IdObjectIiLl0EEENS_3PtrINS2_13IBufferSourceEEES4_PS6_EC1Ev(ptr noundef nonnull align 8 dereferenceable(104) %19)
          to label %20 unwind label %46

20:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  %21 = call i64 @sysconf(i32 noundef 30) #6
  store i64 %21, ptr %9, align 8, !tbaa !9
  %22 = getelementptr inbounds %"class.vl::database::BufferManager", ptr %10, i32 0, i32 0
  %23 = load i64, ptr %22, align 8, !tbaa !11
  %24 = load i64, ptr %9, align 8, !tbaa !9
  %25 = invoke noundef i64 @_ZN2vl8database13IntUpperBoundImEET_S2_S2_(i64 noundef %23, i64 noundef %24)
          to label %26 unwind label %50

26:                                               ; preds = %20
  %27 = getelementptr inbounds %"class.vl::database::BufferManager", ptr %10, i32 0, i32 0
  store i64 %25, ptr %27, align 8, !tbaa !11
  %28 = getelementptr inbounds %"class.vl::database::BufferManager", ptr %10, i32 0, i32 0
  %29 = load i64, ptr %28, align 8, !tbaa !11
  %30 = icmp ugt i64 %29, 0
  br i1 %30, label %31, label %55

31:                                               ; preds = %26
  %32 = getelementptr inbounds %"class.vl::database::BufferManager", ptr %10, i32 0, i32 2
  store i64 64, ptr %32, align 8, !tbaa !26
  br label %33

33:                                               ; preds = %42, %31
  %34 = getelementptr inbounds %"class.vl::database::BufferManager", ptr %10, i32 0, i32 0
  %35 = load i64, ptr %34, align 8, !tbaa !11
  %36 = getelementptr inbounds %"class.vl::database::BufferManager", ptr %10, i32 0, i32 2
  %37 = load i64, ptr %36, align 8, !tbaa !26
  %38 = sub i64 %37, 1
  %39 = shl i64 2, %38
  %40 = and i64 %35, %39
  %41 = icmp eq i64 %40, 0
  br i1 %41, label %42, label %54

42:                                               ; preds = %33
  %43 = getelementptr inbounds %"class.vl::database::BufferManager", ptr %10, i32 0, i32 2
  %44 = load i64, ptr %43, align 8, !tbaa !26
  %45 = add i64 %44, -1
  store i64 %45, ptr %43, align 8, !tbaa !26
  br label %33, !llvm.loop !29

46:                                               ; preds = %3
  %47 = landingpad { ptr, i32 }
          cleanup
  %48 = extractvalue { ptr, i32 } %47, 0
  store ptr %48, ptr %7, align 8
  %49 = extractvalue { ptr, i32 } %47, 1
  store i32 %49, ptr %8, align 4
  br label %56

50:                                               ; preds = %20
  %51 = landingpad { ptr, i32 }
          cleanup
  %52 = extractvalue { ptr, i32 } %51, 0
  store ptr %52, ptr %7, align 8
  %53 = extractvalue { ptr, i32 } %51, 1
  store i32 %53, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  call void @_ZN2vl11collections10DictionaryINS_8database8IdObjectIiLl0EEENS_3PtrINS2_13IBufferSourceEEES4_PS6_ED1Ev(ptr noundef nonnull align 8 dereferenceable(104) %19) #6
  br label %56

54:                                               ; preds = %33
  br label %55

55:                                               ; preds = %54, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  ret void

56:                                               ; preds = %50, %46
  call void @_ZN2vl8SpinLockD1Ev(ptr noundef nonnull align 8 dereferenceable(16) %17) #6
  br label %57

57:                                               ; preds = %56
  %58 = load ptr, ptr %7, align 8
  %59 = load i32, ptr %8, align 4
  %60 = insertvalue { ptr, i32 } poison, ptr %58, 0
  %61 = insertvalue { ptr, i32 } %60, i32 %59, 1
  resume { ptr, i32 } %61
}

declare void @_ZN2vl8SpinLockC1Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #2

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

; Function Attrs: nounwind
declare i64 @sysconf(i32 noundef) #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN2vl8database13IntUpperBoundImEET_S2_S2_(i64 noundef, i64 noundef) #4

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

; Function Attrs: nounwind
declare void @_ZN2vl8SpinLockD1Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #3

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 = { "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 "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 = { 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 #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, !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, !10, i64 0}
!12 = !{!"_ZTSN2vl8database13BufferManagerE", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !13, i64 32, !10, i64 48, !15, i64 56}
!13 = !{!"_ZTSN2vl8SpinLockE", !14, i64 0, !10, i64 8}
!14 = !{!"_ZTSN2vl6ObjectE"}
!15 = !{!"_ZTSN2vl11collections10DictionaryINS_8database8IdObjectIiLl0EEENS_3PtrINS2_13IBufferSourceEEES4_PS6_EE", !14, i64 0, !16, i64 8, !21, i64 56}
!16 = !{!"_ZTSN2vl11collections10SortedListINS_8database8IdObjectIiLl0EEES4_EE", !17, i64 0}
!17 = !{!"_ZTSN2vl11collections8ListBaseINS_8database8IdObjectIiLl0EEES4_EE", !18, i64 0, !10, i64 24, !20, i64 32}
!18 = !{!"_ZTSN2vl11collections9ArrayBaseINS_8database8IdObjectIiLl0EEEEE", !19, i64 0, !6, i64 8, !10, i64 16}
!19 = !{!"_ZTSN2vl11collections9ListStoreINS_8database8IdObjectIiLl0EEELb1EEE", !14, i64 0}
!20 = !{!"bool", !7, i64 0}
!21 = !{!"_ZTSN2vl11collections4ListINS_3PtrINS_8database13IBufferSourceEEEPS4_EE", !22, i64 0}
!22 = !{!"_ZTSN2vl11collections8ListBaseINS_3PtrINS_8database13IBufferSourceEEEPS4_EE", !23, i64 0, !10, i64 24, !20, i64 32}
!23 = !{!"_ZTSN2vl11collections9ArrayBaseINS_3PtrINS_8database13IBufferSourceEEEEE", !24, i64 0, !6, i64 8, !10, i64 16}
!24 = !{!"_ZTSN2vl11collections9ListStoreINS_3PtrINS_8database13IBufferSourceEEELb0EEE", !14, i64 0}
!25 = !{!12, !10, i64 8}
!26 = !{!12, !10, i64 16}
!27 = !{!12, !10, i64 24}
!28 = !{!12, !10, i64 48}
!29 = distinct !{!29, !30}
!30 = !{!"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"

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN2vl8database13BufferManagerC2Emm(ptr noundef nonnull align 8 dereferenceable(168) %0, i64 noundef %1, i64 noundef %2) unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  store i64 %1, ptr %0, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  store i64 %2, ptr %4, align 8, !tbaa !23
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  store i64 0, ptr %5, align 8, !tbaa !24
  %6 = getelementptr inbounds i8, ptr %0, i64 24
  store volatile i64 0, ptr %6, align 8, !tbaa !25
  %7 = getelementptr inbounds i8, ptr %0, i64 32
  tail call void @_ZN2vl8SpinLockC1Ev(ptr noundef nonnull align 8 dereferenceable(16) %7)
  %8 = getelementptr inbounds i8, ptr %0, i64 48
  store volatile i64 0, ptr %8, align 8, !tbaa !26
  %9 = getelementptr inbounds i8, ptr %0, i64 56
  invoke void @_ZN2vl11collections10DictionaryINS_8database8IdObjectIiLl0EEENS_3PtrINS2_13IBufferSourceEEES4_PS6_EC1Ev(ptr noundef nonnull align 8 dereferenceable(104) %9)
          to label %10 unwind label %18

10:                                               ; preds = %3
  %11 = tail call i64 @sysconf(i32 noundef 30) #4
  %12 = load i64, ptr %0, align 8, !tbaa !5
  %13 = tail call noundef i64 @_ZN2vl8database13IntUpperBoundImEET_S2_S2_(i64 noundef %12, i64 noundef %11)
  store i64 %13, ptr %0, align 8, !tbaa !5
  %.not = icmp eq i64 %13, 0
  br i1 %.not, label %20, label %.preheader

.preheader:                                       ; preds = %10, %.preheader
  %storemerge = phi i64 [ %14, %.preheader ], [ 64, %10 ]
  %14 = add i64 %storemerge, -1
  %15 = shl i64 2, %14
  %16 = and i64 %15, %13
  %17 = icmp eq i64 %16, 0
  br i1 %17, label %.preheader, label %.loopexit, !llvm.loop !27

18:                                               ; preds = %3
  %19 = landingpad { ptr, i32 }
          cleanup
  tail call void @_ZN2vl8SpinLockD1Ev(ptr noundef nonnull align 8 dereferenceable(16) %7) #4
  resume { ptr, i32 } %19

.loopexit:                                        ; preds = %.preheader
  store i64 %storemerge, ptr %5, align 8, !tbaa !24
  br label %20

20:                                               ; preds = %.loopexit, %10
  ret void
}

declare void @_ZN2vl8SpinLockC1Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #1

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

; Function Attrs: nounwind
declare i64 @sysconf(i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN2vl8database13IntUpperBoundImEET_S2_S2_(i64 noundef, i64 noundef) local_unnamed_addr #3

; Function Attrs: nounwind
declare void @_ZN2vl8SpinLockD1Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #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 = { "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 = { 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 = { 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, !7, i64 0}
!6 = !{!"_ZTSN2vl8database13BufferManagerE", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !7, i64 48, !12, i64 56}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSN2vl8SpinLockE", !11, i64 0, !7, i64 8}
!11 = !{!"_ZTSN2vl6ObjectE"}
!12 = !{!"_ZTSN2vl11collections10DictionaryINS_8database8IdObjectIiLl0EEENS_3PtrINS2_13IBufferSourceEEES4_PS6_EE", !11, i64 0, !13, i64 8, !19, i64 56}
!13 = !{!"_ZTSN2vl11collections10SortedListINS_8database8IdObjectIiLl0EEES4_EE", !14, i64 0}
!14 = !{!"_ZTSN2vl11collections8ListBaseINS_8database8IdObjectIiLl0EEES4_EE", !15, i64 0, !7, i64 24, !18, i64 32}
!15 = !{!"_ZTSN2vl11collections9ArrayBaseINS_8database8IdObjectIiLl0EEEEE", !16, i64 0, !17, i64 8, !7, i64 16}
!16 = !{!"_ZTSN2vl11collections9ListStoreINS_8database8IdObjectIiLl0EEELb1EEE", !11, i64 0}
!17 = !{!"any pointer", !8, i64 0}
!18 = !{!"bool", !8, i64 0}
!19 = !{!"_ZTSN2vl11collections4ListINS_3PtrINS_8database13IBufferSourceEEEPS4_EE", !20, i64 0}
!20 = !{!"_ZTSN2vl11collections8ListBaseINS_3PtrINS_8database13IBufferSourceEEEPS4_EE", !21, i64 0, !7, i64 24, !18, i64 32}
!21 = !{!"_ZTSN2vl11collections9ArrayBaseINS_3PtrINS_8database13IBufferSourceEEEEE", !22, i64 0, !17, i64 8, !7, i64 16}
!22 = !{!"_ZTSN2vl11collections9ListStoreINS_3PtrINS_8database13IBufferSourceEEELb0EEE", !11, i64 0}
!23 = !{!6, !7, i64 8}
!24 = !{!6, !7, i64 16}
!25 = !{!6, !7, i64 24}
!26 = !{!6, !7, i64 48}
!27 = distinct !{!27, !28}
!28 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass